public bool Insert(User o) { if (o == null || o.Username == null || o.Password == null || o.Email == null) return false; var command = _database.CreateCommand(SQL_INSERT); _database.DefineParameter(command, "@username", DbType.String, o.Username); _database.DefineParameter(command, "@password", DbType.String, o.Password); _database.DefineParameter(command, "@email", DbType.String, o.Email); return _database.ExecuteNonQuery(command) == 1; }
public UserRegistrationViewModel(User user, IManager manager) { this.user = user; this.manager = manager; }
public UserRegistrationViewModel(IManager manager) { this.user = new User(); this.manager = manager; }
/// <summary> /// Logins the specified user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">Invalid user!</exception> public void Login(User user) { if (user == null) throw new ArgumentNullException("Invalid user!"); if (string.IsNullOrEmpty(user.Username)) throw new InvalidUserException("No username provided!"); if (string.IsNullOrEmpty(user.Password)) throw new InvalidUserException("No password provided!"); if (!Exist(user.Username)) throw new LoginException("User does not exist!"); try { if (IsValid(user)) currentUser = user; } catch (Exception) { throw; } }
/// <summary> /// Updates the user. /// </summary> /// <param name="user">The user.</param> /// <exception cref="DataAccessException">Cannot update user!</exception> public void UpdateUser(User user) { if (!userDao.Update(user)) throw new DataAccessException("Cannot update user!"); }
/// <summary> /// Removes the user. /// </summary> /// <param name="user">The user.</param> /// <exception cref="System.ArgumentNullException">Invalid user!</exception> /// <exception cref="DataAccessException">Cannot remove user!</exception> public void RemoveUser(User user) { if (user == null) throw new ArgumentNullException("Invalid user!"); if (!userDao.Delete(user.Username)) throw new DataAccessException("Cannot remove user!"); }
/// <summary> /// Creates the user. /// </summary> /// <param name="user">The user.</param> /// <exception cref="System.ArgumentNullException">Invalid user argument</exception> /// <exception cref="DataAccessException">Cannot create user!</exception> private void CreateUser(User user) { if (!userDao.Insert(user)) throw new ArgumentException("Invalid user user!"); }
/// <summary> /// Registrates the specified user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">Invalid user!</exception> /// <exception cref="UserException">Cannot registrate user</exception> public void Registrate(User user) { if (user == null) throw new ArgumentNullException("Invalid user!"); if (string.IsNullOrEmpty(user.Username)) throw new InvalidUserException("No username provided!"); if (string.IsNullOrEmpty(user.Password)) throw new InvalidUserException("No password provided!"); if (string.IsNullOrEmpty(user.Email)) throw new InvalidUserException("No email provided"); if (Exist(user.Username)) throw new RegistrationException("User already exists!"); try { CreateUser(user); } catch (Exception) { // TODO: user logger throw; } currentUser = user; }
/// <summary> /// Determines whether the specified user is valid. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="UserException"> /// User does not exist! /// or /// Invalid username! /// or /// Invalid password! /// </exception> private bool IsValid(User user) { if (user == null) return false; var dbUser = userDao.FindById(user.Username); if (dbUser == null) throw new InvalidUserException("User does not exist!"); if (!user.Username.Equals(dbUser.Username)) throw new LoginException("Invalid username!"); if (!user.Password.Equals(dbUser.Password)) throw new LoginException("Invalid password!"); return true; }
public UserLoginViewModel(User user, IManager manager) { this.user = user; this.manager = manager; ConfigureValidation(); }
/// <summary> /// Initializes a new instance of the <see cref="UserLoginViewModel"/> class. /// </summary> public UserLoginViewModel(IManager manager) { this.user = new User(); this.manager = manager; ConfigureValidation(); }