public bool AddUser(NewUser user)
        {
            if (!user.Password.Equals(user.RepeatPassword))
                user.AddError("Oba hasła muszą być identyczne");
            if (this.repository.UserExists(user.UserName))
                user.AddError("Użytkownik o takiej nazwie już istnieje");

            if (user.IsValid)
            {
                this.repository.AddUser(user);
                return true;
            }
            return false;
        }
        public void AddUser(NewUser user)
        {
            if (user != null)
            {
                User toAdd = new User()
                {
                    Email = user.Email == null ? string.Empty : user.Email,
                    Name = user.UserName,
                    Password = HashPassword(user.Password),
                    RoleID = user.RoleID,
                };

                SPDatabase.DB.Users.AddObject(toAdd);
                SPDatabase.DB.SaveChanges();
            }
        }
 private void btnAddUser_Click(object sender, EventArgs e)
 {
     lblValidation.Text = string.Empty;
     NewUser user = new NewUser()
     {
         Email = tbNewEmail.Text,
         Password = tbNewPassword.Text,
         RepeatPassword = tbNewRepeatPassword.Text,
         UserName = tbNewUsername.Text,
         RoleID = RoleController.Instance.GetRoleId(cbRoles.SelectedItem.ToString())
     };
     if (!UserController.Instance.AddUser(user))
     {
         string errors = string.Empty;
         foreach (string error in user.Errors)
             errors = errors + error + "\n";
         lblValidation.Text = errors;
     }
     else
     {
         Clear();
         FillWithUsers();
     }
 }