• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Need Help Building My First Class

I'm building my first class for my website project.  The Class will need to define my User entity as well as contain some subroutines for SelectUser, UpdateUser, DeleteUser etc etc.  I have no problem with the subroutines.  For some reason I can't for the life of me figure out where and how i define my "User".  Can someone show me an example of how to architect this class.   Let's just assume that  a  User will have the following properties

ID
FirstName
LastName
Email
Address
IsActive


And then how i would instantiate an instance of a User object on one of my pages.  Or basically, how i'm going to "tie it together" into one of my pages.  For instance, my login page.
0
davidcahan
Asked:
davidcahan
  • 2
  • 2
2 Solutions
 
milduraitCommented:
Here's some basics for you (see code below stored as .vb file in your App_Code folder).
<%
    dim oU as new MyProject.User
%>

To tie it together, you would hold UserID, Email, LoggedIn status in Session variables.
Namespace MyProject
 
   Public Class User
          Public FirstName as string
          Public LastName as string
          Public Email as string
          Public IsActive as boolean
 
          Public Function GetUserIDByEmail(ByValue E as string) as long
               dim UID as long     
              .... your script to query db and return userid
              return UID
          End Function
 
          Public Function CheckPassword(ByVal UID as long,PWD as string) as boolean
              dim PwdCorrect as boolean = false
             .... your script to test password
              return PwdCorrect
          End Function
 
          Public Sub InitialiseUser()
             FirstName = nothing
             LastName = nothing
             Email = Nothing
             Address = nothing
             Active = nothign
          End Sub
 
          Public Function GetUser(ByVal UID as long) as long
             ... your script to read user properties from db
             Return UID 
         end function
 
          Public Function SetUser(ByVal UID as long) as long
             ... your script to update database user properties 
             Return UID 
         end function
 
    End Class
End Namesapce

Open in new window

0
 
davidcahanAuthor Commented:
very nice....could you show me an example of what it would look like if i were returning a whole user record.  for instance.  if i had a sub called

Public function getUser(byVal UserID as Integer) as User

     DO I DIM A USER IN HERE?  dim u as New User()

    return u
End Function
0
 
milduraitCommented:
This is where you would read the values from your database into your object properties.
My example below assumes that i have built a connectivity class to setup and close adodb.recordset objects.

Dim oC as new MyProject.Connectivity
dim rs as adodb.recordset = oC.odbs("SELECT * FROM tblUser WHERE iUserID=" & UserID)
With rs
  If .eof = false then
           FirstName = .fields("sUserFirstName").value
           LastName = .fields("sUserLastName").value
           Email = .fields("sUserEmail").value
           Address = .fields("sUserAddress").value
           IsActive = .fields("bUserActive").value
  else
       Call Initialise()
  end if
End with
oC = nothing

Open in new window

0
 
davidcahanAuthor Commented:
thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now