Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 853923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:50:20+00:00 2026-05-15T07:50:20+00:00

I’ve built a UserRepository interface to communicate with my LINQ to SQL Data layer,

  • 0

I’ve built a UserRepository interface to communicate with my LINQ to SQL Data layer, but I’m trying to figure out how to implement validation.

Here is what my AddUser subroutine looks like

Public Sub AddUser(ByVal about As String, ByVal birthdate As DateTime, ByVal openid As String, ByVal regionid As Integer, ByVal website As String) Implements IUserRepository.AddUser
    Dim user = New User
    user.About = about
    user.BirthDate = birthdate
    user.LastSeen = DateTime.Now
    user.MemberSince = DateTime.Now
    user.OpenID = openid
    user.RegionID = regionid
    user.UserName = String.Empty
    user.WebSite = website

    dc.Users.InsertOnSubmit(user)
    dc.SubmitChanges()
End Sub

And then my controller will simply call AddUser(...)

But I haven’t the foggiest idea on how to implement both client side and server side validation on this.
(I think I would prefer to use jQuery AJAX and do all of the validation on the server, but I’m totally open to opinions)

EDIT:

@vijaysylvester‘s answer was perfect, I just thought I would show a code example of how I implemented it.

UserService.vb

Imports System.ComponentModel.DataAnnotations

Namespace Domain

    <MetadataType(GetType(UserMetaData))> _
    Partial Public Class User : End Class

    Public Class UserMetaData

        <Required(ErrorMessage:="Username is required.")> _
        <StringLength(30, ErrorMessage:="Username cannot exceed 30 characters.")> _
        Public UserName As String

        <StringLength(50, ErrorMessage:="Email Address cannot exceed 50 characters.")> _
        <RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9+)*\\.([a-z]{2,4})$", ErrorMessage:="Not a valid email address.")> _
        Public Email As String

        <StringLength(256, ErrorMessage:="Web Address cannot exceed 256 characters.")> _
        Public WebSite As String

        <StringLength(4000, ErrorMessage:="Profile cannot exceed 4000 characters.")> _
        Public About As String

    End Class

#Region "Interface"
    Public Interface IUserService
        Sub UpdateUser(ByVal id As Integer, ByVal about As String, ByVal birthdate As DateTime, ByVal openid As String, ByVal regionid As Integer, ByVal username As String, ByVal website As String)
        Sub UpdateUserReputation(ByVal id As Integer, ByVal AmountOfReputation As Integer)
        Sub CloseUser(ByVal id As Integer)
        Sub OpenUser(ByVal id As Integer)
        Function GetAllUsers() As IList(Of User)
        Function GetUserByID(ByVal id As Integer) As User
    End Interface
#End Region


#Region "Service"
    Public Class UserService : Implements IUserService

        Private _UserRepository As IUserRepository

        Public Sub New(ByVal UserRepository As IUserRepository)
            _UserRepository = UserRepository
        End Sub

        Public Sub UpdateUser(ByVal id As Integer, ByVal about As String, ByVal birthdate As Date, ByVal openid As String, ByVal regionid As Integer, ByVal username As String, ByVal website As String) Implements IUserService.UpdateUser
            Dim user = _UserRepository.GetUserByID(id)
            user.About = about
            user.BirthDate = birthdate
            user.RegionID = regionid
            user.UserName = username
            user.WebSite = website

            _UserRepository.UpdateUser(user)
        End Sub

        ''# And the rest of my methods.
    End Class
End Namespace
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:50:21+00:00Added an answer on May 15, 2026 at 7:50 am

    Though it is meaningful to do validations in server side and client side manually , I would say one can go with open source validation Frameworks such as XVal .

    Check out the link below.

    XVal reference

    It is as easy as just configuring the properties that needs to be validated.

    E.g.,

    [Required] [StringLength(50)] public string Name { get; set; }
    

    The code snippet above checks if Name is a valid string and its size is not more than 50.

    There are numerous built in validators (including Regular Expressions) , which we can make use of for different data types such as Date.

    Hope this helps.

    Thanks ,
    Vijay.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.