| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

UserManagement Class Code

Page history last edited by PBworks 9 years, 7 months ago

This is code written in C# to give an idea of a framework for a UserManagement class. It relies on the functions in DatabaseCommon (the C# version) - which are also in DBOperations. It demonstrates a class that uses Static methods to return values from the database. It should give students a framework to make calls to the database. It also demonstrates encapsulating code into classes to organize your code. As part of assignments, students will add functions to this like validateUser, addUser, etc....

 

// Dependencies are DatabaseCommon class for accessing the database

   public class UserManagement
    {
        public UserManagement()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static String userReturnPage(System.Web.SessionState.HttpSessionState s)
        {
            if (UserManagement.isLoggedIn(s))
            {
               // This answers the page that the user should be routed to based on whether they are logged in or not

                return "~/main/default_loggedIn.aspx";
            }
            else
            {
                return "~/main/default.aspx";
            }
        }


        public static Boolean isLoggedIn(System.Web.SessionState.HttpSessionState s)
        {
          // When the user logs in , the UserID of the user should be stored in the session variable
          // under the key user_id

            return (Convert.ToInt32(s["user_id"]) > 0);
        }

public static DataSet getUser(int UserID)
        {
            DatabaseCommon db = new DatabaseCommon();
            Dictionary<string, object> Parameters = new Dictionary<string, object>();
            Parameters.Add("@UserID", UserID);
            return (DataSet)db.runStoredProcedure("sp_GetUser", Parameters);
        }
}

 

 

Comments (0)

You don't have permission to comment on this page.