vb.net - ASP.NET MVC - How do I implement validation when using Data Repositories? (Visual Basic) -


I have created a UserRepository interface to communicate with the SQL Data Layer from my LINQ, but I want to know that How to implement validation

This is how it looks like my addUser sub-routine

  public sub addUser (as by string as byVal, date-time birth as born Date, as well as the OpenID string, by field field integer, as the ByVal website string) IUserRepository.AddUser Dim User = About the new user user.About = user.BirthDate = Date of birth user.LastSeen = DateTime.Now user.MemberSince = DateTime.Now user.OpenID = openid user.RegionID = regionId user.UserName = String.Empty user.We BSite = website dc.Users.InsertOnSubmit (user) dc.SubmitChanges () End Sub  

And then my controller will simply call adduser (...) < / P>

But I do not have the most awkward idea about implementing both client side and server side verification on it.
(i think i

edit:

@ 's right, to use jQuery's AJAX and on the server See all the assumptions, but I'm completely open to opinions) I thought I would show a code example of how I implemented it.

UserService.vb

  Import the System.ComponentModel.DataAnnotations namespace domain & lt; Metadata type (GetMyTata) (UserMetaData) & gt; _ Partial Public Class User: And Class Public Class Username Metadata & lt; Required (error message: "user name is required.") & Gt; _ & Lt; String Lang (30, Error Message: "" The user name can not be more than 30 characters. ") & Gt; _ As a public username string & lt; String Lang (50, Error Message: "Email Address can not be more than 50 characters.") & Gt; _ & Lt; RegularExpression ("^ [a-z0- 9_ \\ + -] + (\\. [A-z0- 9_ \\ + -] +) * @ [a-z0-9 -] + (\\. [A-z0-9 +] * \\. ([Az] {2,4}) $ ", error message: =" no valid email address. ") & Gt; _ public email as string; string Lang (256, error message: = "web address can not be more than 256 characters.") & Gt; _ string as public website & lt; string lang (4000, error message: = "profile no more than 4000 characters May be. ") & Gt; _ String ending class #Region about the public appearance is" Interface " Public Interface IUserService Sub UpdateUser (ByVal ID integer, as String about ByVal, ByVal Date of Birth Date, ByVal as the openid string, ByVal integer as regionId, ByVal as the user name string form In the form of ByVal website string) Sub UpdateUserReputation (as ByVal ID integer, ByVal AmountOfReputation as integer) Sub CloseUser (as ByVal ID integer) Sub OpenUser (ByVal ID integer) User Interface User Interface #END Area #Region "Service" Folk Class UserService: IUserService Personal _UserRepository Tool as IUserRepository Public Sub New as the Maroho GetAllUsers () as the IList (user's) function GetUserByID (byVal ID integer) (ByVal UserRepository as the IUserRepository) _UserRepository = UserRepository End Sub People Sub UpdateUser (ByVal id integer, as in the form of the string, in the form of date, as the date of birth, as in the form of volt openID I, as the bi voltage ionid integer, byVal as the user name string, as the ByVal website string) IUserService.UpdateUser Dim User = _UserRepository.GetUserByID (user.BirthDate = Date of birth user.RegionID = regionId user. UserName = Username user.WebSite id) about user.About = = website _ user repository.update user (user) and all '' # and my remaining methods end class namespace name  

however this is the case R is the side and client is important to assumptions side manually, I would say that no open source recognized frameworks such as can be with XVal.

Check the link below.

It is as easy as the properties need to be configured.

  [required] [string lamps (50)] public string name {get; Set; }  

Code snippet above the check if the name is a valid string and its size is no more than 50.

Many of the valators are manufactured ( including

hope this helps.

Thanks, Victory.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -