C# - Handing Complex Validation Scenarios In MVC?

Jan 15, 2010

I'm been working on a GetRuleViolations() method for my User class, but I'm getting a little hung up on on something:

What happens when different actions require different business rules?

My User table has the following columns: Id, UserRoleId, Username, and Password. Several actions involving User are possible (create new user, edit user, set/reset password, and log in), and the business rules for each are not always the same.

For example, when users log in, they are required to enter a password, but when admins create a new user, entering a password is not even an option. And in the case of setting/resetting a password, the password needs to be entered twice, and the two values need to be an exact match. What is the best way to handle this complexity? Is there some kind of design pattern to allow the right GetRulesViolations() method to be selected for the right circumstance?

View 2 Replies


Similar Messages:

MVC :: Scenarios Where Data Validation Is Done In The Viewmodel Not The Model?

Jun 8, 2010

point out an example or tutorial online that shows where data validation is done in the viewmodelas against the model? i saw a number of posts where that method is recommended..i dont really agree with it but i would like to see how it would work out..

View 2 Replies

How To Make Validation Optional For A Complex Type In Mvc

Feb 23, 2011

I want to display an editor for a type User. User contains a field Address of type Address. I made an editor template for the type Address so that it is reusable.

I don't want the field Address to be required for creating a user. But some fields are required for Address, for example country, state etc.

I want to validate Address if I receive any data for it, if I don't receive anything, then I don't want to return any validation error to the UI for Address. I would return only validation errors for User then.

View 1 Replies

How To Manage Complex Data Entry Validation

Oct 18, 2010

I feel like I am fighting against the current when I develop ASP.NET Webform apps. I frequently run into the same problems, and while I eventually find some kind of workaround i'm never fully satisfied with the results.

Here is an example of a typical problem:

The design requires a grid or grid-like result set. This result set is pulled from a database, however, there are additional controls on each row that are not data bound, but their contents are used to insert data into other records.

A good example of this would be displaying a list of products, then adding selected products to a shopping cart based on values entered into quantity fields, and options selected per product. Throw into the mix that you have to allow multiple lines to be added to the cart at the same time, and it starts to get more complex.

Let's add to that mix that you can't select certain products together (mutually exclusive), that you can only select a certain number of one product, but not another, that prices may change while the user is selecting their items, that you you get an overall discount per item based on quantity purchased (both per item and overall order), that you are using a line of credit and cannot exceed the line of credit, nor can you buy more of a given item than an arbitrary amount set in your account or in the product by your account representitive (think certain over the counter medications that the government limits how many you can buy), etc.. etc.. etc..

What starts out as a simple grid with an add to cart becomes a hopeless mess of business logic, which then of course requires validation and notification to the user of various errors in their choices.

How does one deal with very complex data entry schemes in asp.net? How do you even begin to design a piece of software to do all this?

View 2 Replies

MVC :: Binding Of Complex Entity Turns Into Validation Error?

Aug 28, 2010

consider classic example: Product and Category editing Product in dropdown Id of Category is selected - Category mapped as object with all fields empty except Id when submitting Product edit form - validation gives an error: "Category name is required" (I have Required attribute on Category Name property)

How deal with such errors if I want to use built-in validation (

[Code]....

Writing custom data binder which would fill all such id-only-objects with values from database comes to mind.

upd: I did small research of mvc code and found out that validation happens before binding - so this solution would't work.

View 13 Replies

MVC :: Dropdownlist Validation Not Working For Complex View Model

Feb 3, 2011

I have a question regarding validation of drop-down list values. I have a view that is bound to a view model type called ReservationData.

This object contains a property CustomerVehicles of type List<VehicleData>. VehicleDatahas two int properties VehicleMakeId and VehicleModelId.

On my view I am trying to loop over the number of items in the CustomerVehicles collection and displaying two dropdowns for each, a vehicle make dropdown and a vehicle model dropdown usingDropDownListFor.

When I try to submit and validate I do not see any validation errors displayed on the screen.

Just in case you are wondering I have added a ValidationMessageFor for each dropdown as well. I am not sure if this is an issue with the structure of my view model and its complexity and how the controls need to be named or how the ids need to be set.

Here is the code for the looping over the collection:

[Code]....

View 11 Replies

Can Get Started With Using WF 4.0 In Typical Website Scenarios?

Apr 5, 2010

I have developed for SharePoint and in those cases it is clear how workflow can (You have documents that needs approval and there are built in SharePoint workflows for this) But now I am doing standard ASP.NET web CRUD apps with WCF. I would like to find a way to get WF 4.0 invovled but I am not sure how to do it and never see any examples....

View 2 Replies

Architecture :: Handle Different Login Scenarios?

Mar 23, 2010

I need to handle 2 different scenarios.1. Webapplication in a Servercenter. A user can authenticate against a companydatabase with an user account that is stored inside the companytable. We provide services to different companies, and every company has their own database. A management database contains the relation of company to database and server. A user need the companyname, username and password to logon.2. Webapplication on a company serverThe services are hosted on hardware inside the companynet. There is only one company to handle, so that a user doesn't need a companyname for login.Whats the best approach for this problem?

View 1 Replies

.net - Multiple Forms Authentication Scenarios On The Same Website?

Mar 23, 2011

Until now, I've always used straightforward Forms Authentication on my community websites, and that one method of authentication, with that one cookie/ticket has been used throughout the website (with varying roles per user also stored in the ticket). I haven't used the built in LogIn controls and instead have always just created my own login/registration form, and written the code to insert into (and authenticate against in the log-in scenario) my bespoke 'Users' table. So I've essentially just been utilizing the .IsAuthenticated() method (to determine if a user is logged in), referenced the UserData property in the ticket (to determine which roles the user belongs to), and set up the 'location' restrictions in the Web.config, so the log-in page is automatically shown for pages that require 'member access' etc.

With my new project, I will need user registration/login for the Forums/Community part of the website only. I then need an additional user registration/login for the Recruitment part of the website (not related in any way to the users that sign up/log in to the Forums/Community part of the site).I was wondering if this possible, and if so, how to go about it?e user registration/sign-in pages might look the same, but my underlying code would would create accounts/authenticate against different DB tables.

View 1 Replies

Can The Facebook C# SDK Support These Typical Site Login/registration Scenarios

Nov 2, 2010

I want to support the following scenarios on my ASP.NET MVC website:First time visitor wants toregister, via facebook connect. I'dlike the user to have an entry in myuser membership table - so I havethem enter a username/password(email gets populated via facebookconnect).Registered user returns to mysite, logged into facebook already.I'd like my site to see they'relogged into facebook already and
auto log them into my membershipsystem.Registered user returns to msite, but is not logged intofacebook.

View 1 Replies

Forms Data Controls :: Javascript Validation For Assigning Validation Group To Validation Summary On Datalist Item Click?

Dec 25, 2010

I am using one datalist control for uploading multiple images.I hv used one Asp:FileUplaod Control and one button in one itemtemplate.I am using reqired field validator and regular expression validator for file upload cntrl I am assigning validation group for both of them on ItemDataBound event of my datalist so that each upload cntrl hv same validaton group as required field and regular expression validator.Now what i want to do is - i want to show my error message in validation summary which is right at the top of the page.I want one know how to write javascript that will assign validation group of my control in datalist on which i click ?

View 1 Replies

MVC :: How To Organize More Complex Routes

Mar 12, 2011

I understand the basics of setting up routes, I am trying to get a handle on how to organize more complex routes. Does the Route name do anything? I havn't seen a place it's actually used. If I have the route: controller/action/id/paramA/paramB/paramC. ParamA-C could be defining multiple parameters so First/Last/Zip or Phone/Zip/Birthday. Is it common practice to name the additional parameters with a generic name like paramA vs trying to differentiate a separate route for each?

Lastly, if you have multiple sites/functional areas in 1 site, lets say the asp.net site, each area MVC, Ajax, Forums ect were all different functional areas. Is it best to create a different group of routes such as hard coding the controller like:

MVC/action/id
Ajax/action/id
Forums/action/id

or is there a better way? What I am running into is 1 piece of the site overriding the other route because of the number/type of parameters.

View 5 Replies

Patterns To Use When Building Complex Web UI?

Jun 24, 2010

I need to implement a wizardy, dynamic UI that uses complex validation of the style:

If A = 1, show controls B, C, D. B is required, C is not, and D is not required must be less than 30 if it is populated.

If A = 2, show controls B, D, E. B is not required, D is required but has no limits, and E is not required.

If B is not null, show controls B, D, E. B is not required, D is required but has no limits, and E is not required.

Historically, I have made my presentation layer as "dumb" as possible in that it is only responsible for capturing user input and binding it to the appropriate domain model. The domain model, in turn, contains the logic needed to validate it's state and that of any child objects, and then communicates any invalid state to the presentation layer via notifications. As such, this requirement for a highly "intelligent" UI represents a departure for me.

I think I have no choice but to construct 2 very similar class hierarchies:

one that will capture presentation business rules (i.e. what fields are visible) and control what renders in the View

one that will capture domain business rules (when field A = X, then field B should be not null and in the range of n to m) to disallow objects with an invalid state from being persisted


Sill I have far more questions than answers on my strategy moving forward. Is there a set of design patterns I can draw on to build such a dynamic UI? I do have the option of using ASP.NET MVC or WebForms, so whichever approach will produce cleaner, testable code is preferred.

View 1 Replies

Complex Filtering In Web Application?

Sep 18, 2010

I need to estimate (and probably build later on) complex filter in ASP.NET WebForms application. The filter has to be mostly based on ASP.NET AJAX or jQuery for high interactivity. The filter has to allow filtering data with complex logical conditions (and, or, braces) and several operators. A user has to be able to save the filter's query and use it (load it) later on (server logic). Moreover there is still discussion about in operator.

Application should provide some graphical filter builder. I want to have full control on set of operands (filtering fields) and operators. The component will be used for all filtering actions in application. My problem is only how to do the UI part - translation of builded "query structure" is not a problem.

Have you ever did something like that? Can you share some experience how to best and fastest build such component? Do I need to develop component or is there any existing one which has at least some of the functionality and can be extended to provide other functionality? Because I'm not very experienced with client side development, I don't know how complex task is developing such component from scratch.

Another possiblity is to define some meta query language and allow users to write the query to some query text box with support for building logical expressions. I have already checked available controls in DevExpress and Telerik toolkits:

DevExpress:

Pros: Really nice visualization, fast. We probably have DevExpress licences. Cons: Tightly coupled with DevExpress grid. Based on documentation no extensibility and no control over operands and operators. It uses operands provided as columns for grid - I need much more. Probably not possible to save and load filters.

Telerik:

Pros: Not coupled with grid, it looks like separate control. Cons: I didn't find documentation - I'm not sure about extensibility but the code looks like it uses some databind control as source of operands = problem. I don't like the visualization. Demo is really slow. We don't have Telerik licences.

View 3 Replies

MVC :: Creating A Complex Form With C#?

Feb 10, 2011

How can I create a form that creates or updates a complex type that takes a form like:[Code]....

I would like to either create two forms one for tblstudent and one for tbldata and tblStudata or create one form for all three and give the illusion of multiple pages. I came across an old Railscast that talks about virtual attributes and a helper called fields_for which helps you switch between model contexts in a single form. Is there a way of achieving this kind of functionality with C# MVC 2 or 3?

If this sort of thing is not possible how else might I be able to handle create/update scenarios without defining two actions amd voews for each table entity I need to work with or god forbid separate controllers?

View 2 Replies

SQL Server :: Auto Generate More Complex ID?

Jul 17, 2010

I really don't know if this Post fit in this Forum section. But here I go. I need some sugestion to develop an ASP.NET code that generate complex IDs / Keys automatically. Let me be more understandable:

I want to create uniquelly IDs with more complex composition (kind of 18958351512783997769711... or crlu0xakecjzlgmjsgnedr55) or something link that (doesn't matter the lenght... those are only examples).

So, I can use that to set COOKIE ID's... PRODUCTS CODE ID's.... CUSTOMER's CART ID's... etc... But it need to generate uniquelly numbers. I don't know if you got my point I hope you did.

View 3 Replies

Proper Implementation Of MVP With Complex Controls?

Jan 20, 2010

I'm currently implementing a project using asp.net, c# and the MVP (Model-View-Presenter) pattern. The main purpose of this solution is to deliver a graph to the consumer, to be used by a variety of systems. It is basically a custom graph server.

The view page in this particular case has an MSChart control on it, which has to be dynamically populated and configured based on parameters in the QueryString. This can be as diverse as totally different types of data sets, display modes and so on, using a lot of the properties of the chart control.

Many of these properties are again of types which are particular to the chart control and would require the same dependencies as the chart control itself if they are to be set by the presenter.

I'm trying to figure out the best way to expose the properties to the presenter so it can work its magic.

Should I:

Just expose the whole chart object and live with a system.web type dependency in the presenter project? Make accessor and translation properties for all of the chart control properties so that I don't have the dependency, but add lots of complexity? Other, that I haven't thought of?

To me it seems that it would be against the MVP pattern to bubble a display control up into the presenter, but it seems that trying to map all the properties to DTOs or similar would be a lot of work that would add a lot of complexity, and while the solution would be somewhat more loosely coupled, I'm not sure the gain would be worth it in this case. How would you implement something like this, given MVP?

View 2 Replies

MVC :: ModelMetadata Property Name For Complex Type?

Feb 3, 2011

[Code]....

[Code]....

How can i get full name of the property ?

View 7 Replies

Web Forms :: Complex Word Doc To Pdf Conversion

Jan 22, 2010

I need to convert the word doc to pdf, ofcourse i did it,But i converted only simple word file that has only strings. But I need to convert the word doc that has images tables with all formatings how Can i achive it.

View 5 Replies

Aligning Complex Images On A Web Page

Jan 17, 2011

i would like to ask what is the best way to position and align images on an HTML web page.

I will have approximately 10 user-controls that each have a set of images on them laid out in a specific pattern, eg - an arc, a circle, straight line, some other sort of curve.

How i can achieve this using best practices?

Update: All the images will be the same size.

View 1 Replies

Consuming .NET Web Services With Complex Types In PHP

Mar 12, 2011

Can i consume .NET web service and use it complex types in PHP?
Example:

[WebMethod]
public DataSet GetData()
{
return new DataSet();
}

Can i consume this method and use DataSet class methods in PHP?

View 1 Replies

MVC :: Using EF4 Complex Types / Properties In Repositories?

Jan 13, 2011

Are there advantages in creating complex types in EF4 Entities and then use the complex properties in the repositories; instead of creating the aggregates in the the repository themselves? I.e. If the customer repository consists of properties of 3 entities: customers, addresses, email would it make sense to create a complex type consisting of the address and email properties, and add them as a complex property of the customer entity then just call the customer entity and the complex property in the repository, rather than just creating the repository class and aggregate the entities in the repository.What are there advantages or disadvantages in doing this in a MVC3 application?

View 10 Replies

Complex Items In WebForms ListView?

Nov 15, 2010

I'm currently using a ListView in my webformsapplication. This ListView generates a table with (currently) three columns. "Username", "Organization" and "Locked". These are represented with string, string and checkbox respectively. The checkbox should postback on change...

Should I use <%# Eval("Username") %> or <asp:Literal blablah> to inject the data? This is more relevant for the checkbox... It seems very "dirty" to write <input type="checkbox" id="something" <%# if ((bool)Eval("Locked") == true) /* some unknown code for outputting "checked" */ ;%> />

Or should I use another container alltogether?

View 1 Replies

MVC :: Razor In WebGrid - Can Use Complex Content

Nov 5, 2010

I am using Razor and MVC 3 WebGrid in ASP.NET MVC 3 Beta.

I have the following:

[Code]....

I am not able to have two ActionLinks on the same column. In this case I get the following error:

The best overloaded method match for 'System.Web.Helpers.WebGrid.Column(string, string, System.Func<dynamic,object>, string, bool)' has some invalid arguments

This is usefull not just for this but to create columns that contains more information then just a field.

I also tried Razor's <text> but no luck ... Maybe I used it wrong.

View 5 Replies

C# - Bind A Complex Dictionary To A Gridview?

Jun 6, 2010

I've used an early binding of a dictionary<string, string> to a gridview to show Urls Text and its HRef as key-value and it works like a charm. But since I want to replace the dictionary with this one :

dictionary<string, LinkInfo>

the binding goes wrong! Should I handle some events like as onItemDataBound or something?
and the LinkInfo structure is:

public struct LinkInfo{
public string href;
public bool Enabled;
}

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved