Example #1
0
        /// <summary>
        /// Purpose: Add new user's information to the DB
        /// Accepts: Hashtable
        /// Returns: int
        /// </summary>
        public int AddUser(Hashtable hsh)
        {
            int newId = -1;
            User usr = new User();
            QuickStart_DBEntities dbContext;

            try
            {
                dbContext = new QuickStart_DBEntities();
                usr.Username = Convert.ToString(hsh["username"]);
                usr.Password = Convert.ToString(hsh["password"]);
                usr.Salutation = Convert.ToString(hsh["salutation"]);
                usr.FirstName = Convert.ToString(hsh["firstName"]);
                usr.LastName = Convert.ToString(hsh["lastName"]);
                usr.Address1 = Convert.ToString(hsh["address1"]);
                usr.Address2 = Convert.ToString(hsh["address2"]);
                usr.City = Convert.ToString(hsh["city"]);
                usr.StateProvinceID = Convert.ToInt32(hsh["stateProv"]);
                usr.ZipPostalCode = Convert.ToString(hsh["zipPC"]);
                usr.Email = Convert.ToString(hsh["email"]);
                usr.IsReceiveNewsletters = Convert.ToBoolean(hsh["newsletters"]);
                usr.Created = DateTime.Now;

                dbContext.AddToUsers(usr);
                dbContext.SaveChanges();
                newId = usr.UserID;
                dbContext.Detach(usr);
            }
            catch (Exception e)
            {
                ErrorLoggerData.ErrorRoutine(e, "UserData", "AddUser");
            }

            return newId;
        }
Example #2
0
        /// <summary>
        /// Purpose: Grabs user information based on ID
        /// Accepts: Int
        /// Returns: Hashtable
        /// </summary>
        public Hashtable GetUserByID(int id)
        {
            User obj = new User();
            QuickStart_DBEntities dbContext;
            Hashtable hsh = new Hashtable();
            try
            {
                dbContext = new QuickStart_DBEntities();
                obj = dbContext.Users.FirstOrDefault(u => u.UserID == id);
                if (obj != null)
                {
                    hsh["userid"] = obj.UserID;
                    hsh["username"] = obj.Username;
                    hsh["password"] = obj.Password;
                    hsh["salutation"] = obj.Salutation;
                    hsh["firstname"] = obj.FirstName;
                    hsh["lastname"] = obj.LastName;
                    hsh["address1"] = obj.Address1;
                    hsh["address2"] = obj.Address2;
                    hsh["city"] = obj.City;
                    hsh["stateprovinceid"] = obj.StateProvinceID;
                    hsh["zippostalcode"] = obj.ZipPostalCode;
                    hsh["email"] = obj.Email;
                    hsh["isreceivenewsletters"] = obj.IsReceiveNewsletters;
                    hsh["created"] = obj.Created;
                    hsh["modified"] = obj.Modified;
                }
            }
            catch (Exception ex)
            {
                ErrorLoggerData.ErrorRoutine(ex, "UserData", "GetUserByID");
            }

            return hsh;
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="userID">Initial value of the UserID property.</param>
 public static User CreateUser(global::System.Int32 userID)
 {
     User user = new User();
     user.UserID = userID;
     return user;
 }
Example #5
0
        /// <summary>
        /// Purpose: Update an existing User in the database
        /// Accepts: Hashtable
        /// Returns: Boolean
        /// </summary>
        public bool UpdateUser(Hashtable hsh)
        {
            bool isSuccess = false;
            User usr = new User();
            QuickStart_DBEntities dbContext;
            try
            {
                dbContext = new QuickStart_DBEntities();

                //Get the user to update based on its id
                int userid = Convert.ToInt32(hsh["userid"]);
                usr = dbContext.Users.FirstOrDefault(u => u.UserID == userid);

                usr.Username = Convert.ToString(hsh["username"]);
                usr.Password = Convert.ToString(hsh["password"]);
                usr.Salutation = Convert.ToString(hsh["salutation"]);
                usr.FirstName = Convert.ToString(hsh["firstName"]);
                usr.LastName = Convert.ToString(hsh["lastName"]);
                usr.Address1 = Convert.ToString(hsh["address1"]);
                usr.Address2 = Convert.ToString(hsh["address2"]);
                usr.City = Convert.ToString(hsh["city"]);
                usr.StateProvinceID = Convert.ToInt32(hsh["stateProv"]);
                usr.ZipPostalCode = Convert.ToString(hsh["zipPC"]);
                usr.Email = Convert.ToString(hsh["email"]);
                usr.IsReceiveNewsletters = Convert.ToBoolean(hsh["newsletters"]);
                //need 'modified' but not 'created' during an update
                usr.Modified = DateTime.Now;

                dbContext.SaveChanges();
                isSuccess = true;
            }
            catch (Exception e)
            {
                ErrorRoutine(e, "UserData", "UpdateUser");
            }

            return isSuccess;
        }