예제 #1
0
        /// <summary>
        /// Delete a User by the primary key
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns></returns>
        public int Delete(User user)
        {
            SqlParameter[] parameters =
            {
                _database.MakeParameter("@UserId", SqlDbType.Int, 4, user.UserId)
            };

            return _database.NonQuery("User_Delete", parameters);
        }
        /// <summary>
        /// Delete a User by the primary key
        /// </summary>
        /// <param name="user"></param>
        public int Delete(User user, string commandText)
        {
            DbParameter[] parameters =
            {
                DbClient.MakeParameter("@UserId",DbType.Int32,4,user.UserId),

            };

            return DbClient.NonQuery(commandText, parameters);
        }
        /// <summary>
        /// Retrieves the selected rows.
        /// </summary>
        /// <returns></returns>
        private List<User> RetrieveSelectedRows()
        {
            List<GridViewRow> selectedRows = RetrieveCheckedRowsFromGridview("selectedRow", manageUsers);
            List<User> selectedPhotos = new List<User>();

            foreach (GridViewRow row in selectedRows)
            {
                User user = new User { UserId = Int32.Parse(manageUsers.DataKeys[row.RowIndex].Value.ToString()) };

                selectedPhotos.Add(user);
            }

            return selectedPhotos;
        }
        /// <summary>
        /// Inserts User into the Users Table
        /// </summary>
        /// <param name="user">A new populated user.</param>
        /// <returns>Insert Count</returns>
        public int Insert(User user, string commandText)
        {
            DbParameter[] parameters =
            {
                    DbClient.MakeParameter("@Email",DbType.String,50,user.Email),
                    DbClient.MakeParameter("@Password",DbType.String,150,user.Password),
                    DbClient.MakeParameter("@FirstName",DbType.String,50,user.FirstName),
                    DbClient.MakeParameter("@LastName",DbType.String,50,user.LastName),
                    DbClient.MakeParameter("@Access",DbType.Byte,1,user.Access),
                    DbClient.MakeParameter("@Website",DbType.String,200,user.Website)

            };

            return DbClient.NonQuery(commandText, parameters);
        }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            IsUserEdit = !string.IsNullOrEmpty(Request.QueryString["uid"]);
            Page.Title = "Add New User - PhotoGallery - By Chucksoft";

            //if in edit mode, retrieve user.
            if (IsUserEdit)
            {
                //Set Edit Text
                h1HeaderLiteral.Text = "Edit User";
                saveLinkButton.Text = "Save";
                Page.Title = "Edit User - PhotoGallery - By Chucksoft";

                if(int.TryParse(Request.QueryString["uid"], out userId))
                {
                    //Retrieve the user by UserId and populate fields on the page.
                   editUser = new UserLogic().RetreiveUserByUserId(userId);
                   PopulateFields();
                }
            }
        }
        /// <summary>
        /// Updates the User table by the primary key, if the User is dirty then an update will occur
        /// </summary>
        /// <param name="user">a populated user</param>
        /// <returns>update count</returns>
        public int Update(User user, string commandText)
        {
            int updateCount = 0;

            if(user.IsDirty())
            {
                DbParameter[] parameters =
                {
                    DbClient.MakeParameter("@UserId",DbType.Int32,4,user.UserId),
                    DbClient.MakeParameter("@Email",DbType.String,50,user.Email),
                    DbClient.MakeParameter("@Password",DbType.String,150,user.Password),
                    DbClient.MakeParameter("@FirstName",DbType.String,50,user.FirstName),
                    DbClient.MakeParameter("@LastName",DbType.String,50,user.LastName),
                    DbClient.MakeParameter("@Access",DbType.Byte,1,user.Access),
                    DbClient.MakeParameter("@Website",DbType.String,200,user.Website)

                };

                updateCount = DbClient.NonQuery(commandText, parameters);

            }

            return updateCount;
        }
예제 #7
0
        /// <summary>
        /// Inserts User into the Users Table
        /// </summary>
        /// <param name="user">A new populated user.</param>
        /// <returns>Insert Count</returns>
        public int Insert(User user)
        {
            SqlParameter[] parameters =
            {
                    _database.MakeParameter("@Email",SqlDbType.NVarChar, 50,user.Email),
                    _database.MakeParameter("@Password",SqlDbType.NVarChar, 150,user.Password),
                    _database.MakeParameter("@FirstName",SqlDbType.NVarChar, 50,user.FirstName),
                    _database.MakeParameter("@LastName",SqlDbType.NVarChar, 50,user.LastName),
                    _database.MakeParameter("@Access",SqlDbType.TinyInt, 1,user.Access),
                    _database.MakeParameter("@Website",SqlDbType.NVarChar, 200,user.Website)
            };

            return _database.NonQuery("User_Insert", parameters);
        }
예제 #8
0
        /// <summary>
        /// Gets the item.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static User GetItem(IDataRecord reader)
        {
            User user = new User
                            {
                                UserId = Convert.ToInt32(reader["UserId"]),
                                Email = Convert.ToString(reader["Email"]),
                                Password = Convert.ToString(reader["Password"]),
                                FirstName = Convert.ToString(reader["FirstName"]),
                                LastName = Convert.ToString(reader["LastName"]),
                                Access = Convert.ToByte(reader["Access"]),
                                Website = Convert.ToString(reader["Website"]),
                                ServiceKey = new Guid(reader["ServiceKey"].ToString())
                            };

            return user;
        }
예제 #9
0
        /// <summary>
        /// Updates the User table by the primary key, if the User is dirty then an update will occur
        /// </summary>
        /// <param name="user">a populated user</param>
        /// <returns>update count</returns>
        public int Update(User user)
        {
            SqlParameter[] parameters =
                {
                    _database.MakeParameter("@UserId",SqlDbType.Int, 4, user.UserId),
                    _database.MakeParameter("@Email",SqlDbType.NVarChar, 50, user.Email),
                    _database.MakeParameter("@Password",SqlDbType.NVarChar, 150, user.Password),
                    _database.MakeParameter("@FirstName",SqlDbType.NVarChar, 50, user.FirstName),
                    _database. MakeParameter("@LastName",SqlDbType.NVarChar, 50, user.LastName),
                    _database.MakeParameter("@Access",SqlDbType.TinyInt, 1, user.Access),
                    _database.MakeParameter("@Website",SqlDbType.NVarChar, 200, user.Website)
                };

            int updateCount = _database.NonQuery("User_Delete", parameters);

            return updateCount;
        }
예제 #10
0
        /// <summary>
        /// Populates the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public User Populate(DbDataReader reader)
        {
            User user = new User();

            using (reader)
            {
                if(reader.Read())
                {
                   user = GetItem(reader);
                }
            }

            return user;
        }
        /// <summary>
        /// Populates the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        internal User Populate(DbDataReader reader)
        {
            User user = new User();

            using (reader)
            {
                while (reader.Read())
                {
                    user = GetItem(reader);
                }
            }

            return user;
        }
예제 #12
0
        /// <summary>
        /// Sets the authorized user.
        /// </summary>
        /// <param name="authorize">The authorize.</param>
        private void SetAuthorizedUser(Authorization authorize)
        {
            User user = authorize.RetrieveUser();

            HttpCookie sessionCookie = new HttpCookie(AdminResources.AdminSessionCookieName);
            sessionCookie["Token"] = new UserLogic().GenerateUserToken(user.ServiceKey);
            sessionCookie["Meat"] = "Chicken";
            sessionCookie.Expires = DateTime.Now.AddMonths(1);

            Authorization.SetUnencryptedCookie(sessionCookie);

            CurrentUser = user;
            Thread.CurrentPrincipal = CurrentUser;
        }
예제 #13
0
 /// <summary>
 /// Inserts User into the Users Table
 /// </summary>
 /// <param name="user">A new populated user.</param>
 /// <returns>Insert Count</returns>
 public int Insert(User user)
 {
     const string sql = "INSERT INTO User (Email, Password, FirstName, LastName, Access, Website)  VALUES (@Email, @Password, @FirstName, @LastName, @Access, @Website)";
     return userDb.Insert(user, sql);
 }
예제 #14
0
 /// <summary>
 /// Updates the specified user.
 /// </summary>
 /// <param name="user">The user.</param>
 public void Update(User user)
 {
     _resource.Update(user);
 }
예제 #15
0
 /// <summary>
 /// Inserts User into the Users Table
 /// </summary>
 /// <param name="user">A new populated user.</param>
 /// <returns>Insert Count</returns>
 public int Insert(User user)
 {
     return userDb.Insert(user, "User_Insert");
 }
예제 #16
0
 /// <summary>
 /// Delete a User by the primary key
 /// </summary>
 /// <param name="user"></param>
 public int Delete(User user)
 {
     return userDb.Delete(user, deleteProcedure);
 }
예제 #17
0
 /// <summary>
 /// Updates the User table by the primary key, if the User is dirty then an update will occur
 /// </summary>
 /// <param name="user">a populated user</param>
 /// <returns>update count</returns>
 public int Update(User user)
 {
     int updateCount = userDb.Update(user, "User_Update");
     return updateCount;
 }
예제 #18
0
        /// <summary>
        /// Handles the Click event of the saveButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void saveButton_Click(object sender, EventArgs e)
        {
            User user = new User
                            {
                                Access = 0,
                                Email = emailAddressTextBox.Text.Trim(),
                                FirstName = firstNameTextBox.Text.Trim(),
                                LastName = lastNameTextBox.Text.Trim(),
                                Website = websiteTextBox.Text.Trim()
                            };

            bool passwordFieldsHaveValues = !string.IsNullOrEmpty(passwordOneTextBox.Text.Trim()) && !string.IsNullOrEmpty(passwordTwoTextBox.Text.Trim());
            bool isValidPassword = true;

            //Check passwords if they exist
            if (passwordFieldsHaveValues)
            {
                isValidPassword = IsValidPassword();

                if(isValidPassword)
                {
                    user.Password = SimpleHash.ComputeHash(passwordOneTextBox.Text.Trim(), SimpleHash.Algorithm.SHA256, new byte[8]);
                }
                else
                {
                    message.Text = "Passwords don't match";
                }
            }
            else
            {
                if(!IsUserEdit)
                {
                    message.Text = "New Users require a password";
                }
            }

            //Check that there is a valid password and the error text is empty
            if (isValidPassword && string.IsNullOrEmpty(message.Text))
            {

                if (IsUserEdit)
                {
                    //If no password values were entered we need to keep the old password.
                    if (!passwordFieldsHaveValues)
                    {
                        user.Password = editUser.Password;
                    }

                    //Set user Id
                    user.UserId = userId;

                    //update the user and display the success message.
                    new UserLogic().Update(user);
                    //message.Text = string.Format(AdminResources.SuccessfulUserUpdate);
                    Response.Redirect("~/Admin/Manage.aspx?a=Users", false);
                }
                else
                {
                    new UserLogic().Add(user);
                    message.Text = string.Format(AdminResources.SuccessfulUserAdd, user.Email);
                }

                //Clears the textboxes
                WebControlUtilities.ClearTextFromControl<TextBox>(Controls);

            }
        }
예제 #19
0
 /// <summary>
 /// Delete a single user
 /// </summary>
 /// <param name="user">The user.</param>
 public void Delete(User user)
 {
     _resource.Delete(user);
 }
예제 #20
0
        /// <summary>
        /// Retrieves the user by token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public User RetrieveUserByToken(string token)
        {
            bool isValidToken = IsValidToken(token);
            User user = new User();

            //if valid token, proceed to use it.
            if (isValidToken)
            {
                string[] tokenSegments = DecryptToken(token);

                Guid serviceKey = new Guid(tokenSegments[1]);
                user = _resource.RetrieveUserByServiceKey(serviceKey);
            }

            return user;
        }
예제 #21
0
        /// <summary>
        /// Gets the first user in the collection
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        private User GetUser(IList<User> users)
        {
            User user = new User();

            if(users.Count > 0)
            {
                user = users[0];
            }

            return user;
        }
예제 #22
0
 /// <summary>
 /// Adds the specified user.
 /// </summary>
 /// <param name="user">The user.</param>
 public void Add(User user)
 {
     _resource.Insert(user);
 }
예제 #23
0
 /// <summary>
 /// Updates the User table by the primary key, if the User is dirty then an update will occur
 /// </summary>
 /// <param name="user">a populated user</param>
 /// <returns>update count</returns>
 public int Update(User user)
 {
     const string sql = "Update User	SET	Email = @Email, Password = @Password, FirstName = @FirstName, LastName = @LastName, Access = @Access,   Website = @Website Where UserId = @UserId ";
     int updateCount = userDb.Update(user, sql);
     return updateCount;
 }