private void simpleButton1_Click(object sender, EventArgs e)
        {
            User users = new User();
            users.Username = txtUserID.Text;
            users.FullName = txtFullName.Text;
            users.Password = "******";
            users.Active = Convert.ToBoolean(IsActive.EditValue);
            users.Deleted = false;

            UserService.SaveUser(users);

            MessageBox.Show("Complete Save", "Information");
        }
        public void SaveUser(User user)
        {
            string saltKey = CreateSalt(7);

            //Getting Encrypted password
            user.Salt = saltKey;
            user.PasswordHash = GetSHA1HashData(user.Password, saltKey);
            user.RegistrationDate = System.DateTime.Now;
            user.UpdatedDate = System.DateTime.Now;

            User existingData = GetUserByID(user.UserID);

            if (existingData == null)
            {
                user.UserGUID = Guid.NewGuid();
                _context.Users.AddObject(user);
            }
            else
            {
                existingData.UserGUID = Guid.NewGuid();
                existingData.UserRoleID = user.UserRoleID;
                existingData.MediaID = user.MediaID;
                existingData.FullName = user.FullName;
                existingData.Gender = user.Gender;
                existingData.NRCNumber = user.NRCNumber;
                existingData.Address1 = user.Address1;
                existingData.Address2 = user.Address2;
                existingData.PhoneNumber = user.PhoneNumber;
                existingData.EmailAddress = user.EmailAddress;
                existingData.Active = user.Active;
                existingData.Deleted = user.Deleted;
                existingData.UpdatedDate = user.UpdatedDate;
                existingData.DateOfBirth = user.DateOfBirth;
                existingData.IsMember = user.IsMember;

                if (!_context.IsAttached(existingData))
                    _context.Users.Attach(existingData);
            }

            _context.SaveChanges();
        }
        /// <summary>
        /// Save user for both Insert and Update purpose 
        /// </summary>
        /// <param name="user">User</param>
        public bool SaveUser(User user)
        {
            string saltKey = CreateSalt(7);
            user.Salt = saltKey;
            user.PasswordHash = GetSHA1HashData(user.Password, saltKey);

            User existingData = new User();
            existingData = GetUserByUserName(user.Username);

            if (existingData != null && existingData.UserID != user.UserID)
            {
                if (existingData.UserID != 0)
                    return false;
            }

            existingData = GetUserByID(user.UserID);

            if (existingData == null)
            {
                user.UserGUID = Guid.NewGuid();
                user.CreatedOn = System.DateTime.Now;
                user.UpdatedOn = System.DateTime.Now;

                _context.Users.AddObject(user);
            }
            else
            {
                existingData.UserGUID = Guid.NewGuid();
                existingData.UserRoleID = user.UserRoleID;
                existingData.PictureID = user.PictureID;
                existingData.FullName = user.FullName;
                existingData.Gender = user.Gender;
                existingData.NRCNumber = user.NRCNumber;
                existingData.Username = user.Username;
                existingData.PasswordHash = user.PasswordHash;
                existingData.Salt = user.Salt;
                existingData.AddressID = user.AddressID;
                existingData.IsActive = user.IsActive;
                existingData.CreatedOn = user.CreatedOn;
                existingData.UpdatedOn = System.DateTime.Now;

                if (!_context.IsAttached(existingData))
                    _context.Users.Attach(existingData);
            }
            _context.SaveChanges();

            return true;
        }
 /// <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;
 }
        /// <summary>
        /// Get user by Username 
        /// </summary>
        /// <param name="username">The username</param>
        /// <param name="password">Password</param>
        /// <param name="fullname">Full Name</param>
        public void InsertUser(string username, string password, string fullname)
        {
            string saltKey = CreateSalt(7);

            User user = new User();
            user.Username = username;
            user.Salt = saltKey;
            user.Fullname = fullname;
            user.PasswordHash = GetSHA1HashData(password, saltKey);

            _context.Users.AddObject(user);
            _context.SaveChanges();
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtUserID.Text.Length > 0)
            {
                if (txtFullName.Text.Length > 0)
                {
                    User user = new User();

                    UserService.InsertUser(txtUserID.Text.ToString(), "password", txtFullName.Text.ToString());

                    grdUsers.DataSource = UserService.GetAllUsers();

                    ClearForm();
                }
                else
                {
                    MessageBox.Show("Please, fill the full name up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtFullName.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please, fill the product name up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserID.Focus();
            }
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtUserID.Text.Length > 0)
            {
                if (txtFullName.Text.Length > 0)
                {
                    User user = new User();

                    //for Edit Data
                    if (UserID.Length > 0)
                    {
                        user.UserID = int.Parse(UserID);
                        user.CreatedOn = Convert.ToDateTime(txtUserID.Tag.ToString());
                    }
                    user.Username = txtUserID.Text.ToString();
                    user.FullName = txtFullName.Text.ToString();
                    user.Password = "******";
                    user.IsActive = Convert.ToBoolean(chkIsActive.EditValue);
                    user.UpdatedOn = DateTime.Now;
                    user.PictureID = zpcUserImage.SavePicture();

                    //for New Data
                    if (UserID.Length < 0)
                    {
                        user.CreatedOn = DateTime.Now;
                    }

                    bool dublicatUser = UserService.SaveUser(user);

                    if (dublicatUser == false)
                    {
                        MessageBox.Show("Login Name is already exit. Please, change the user id up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtUserID.Focus();
                    }
                    grdUsers.DataSource = UserService.GetAllUsers();

                    ClearForm();
                }
                else
                {
                    MessageBox.Show("Please, fill the full name up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtFullName.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please, fill the product name up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserID.Focus();
            }
        }