/// <summary> /// Verifying user email /// </summary> /// <param name="token">Email verification token</param> /// <returns>true - if succeded</returns> public async Task <bool> VerifyEmail(string token) { if (string.IsNullOrEmpty(token)) { throw new ArgumentNullException(nameof(token)); } BllUser user = (await context.UserStore.GetByPredicate(t => t.ActivationToken == token)).ToBllUser(); if (user == null) { return(false); } if (user.IsEmailConfirmed) { return(false); } user.IsEmailConfirmed = true; await context.UserStore.UpdateAsync(user.ToDalUser()); await context.UserStore.AddToRoleAsync(user.ToDalUser(), "user"); return(true); }
/// <summary> /// Create new user /// </summary> /// <param name="user">New user</param> /// <returns>Id of created user</returns> public async Task <int> Register(BllUser user) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } var dbUser = await context.UserStore.FindByNameAsync(user.Login); if (dbUser == null) { if (await context.UserStore.IsEmailExist(user.Email)) { return((int)UserVerificationResult.ExistWithSameEmail); } int userId = await context.UserStore.CreateAsync(user.ToDalUser()); context.Commit(); return(userId); } else { return((int)UserVerificationResult.ExistWithSameLogin); } }
/// <summary> /// Remove existing User. /// </summary> /// <param name="user"> User to remove.</param> public void DeleteUser(BllUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } repository.Delete(user.ToDalUser()); service.Save(); }
public void Update(BllUser entity) { if (entity == null) { return; } UnitOfWork?.UserRepository?.Update(entity.ToDalUser()); UnitOfWork?.Commit(); }
public void AddUser(BllUser user) { uow.Users.Create(user.ToDalUser()); uow.Profiles.Create(new DalProfile() { Id = user.Id }); uow.Commit(); }
public void UpdateUser(BllUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } userRepository.Update(user.ToDalUser()); uow.Commit(); }
public void Create(BllUser entity) { //TODO: throw of not to throw if (entity == null) { return; } UnitOfWork?.UserRepository?.Create(entity.ToDalUser()); UnitOfWork?.Commit(); }
public void UpdateUser(BllUser user) { try { userRepository.Update(user.ToDalUser()); } catch (InvalidOperationException e) { logger.Warn(e.Message); throw; } }
/// <summary> /// Creates new User. /// </summary> /// <param name="user"> User to create.</param> /// <exception> UserEmailAlreadyExistsException if user with specified email already exists.</exception> public void CreateUser(BllUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var existingUser = repository.GetByPredicate(u => u.Email == user.Email).SingleOrDefault(); if (existingUser != null) { throw new UserEmailAlreadyExistsException(user.Email); } repository.Create(user.ToDalUser()); service.Save(); }
private void OnDeleted(object sender, BllUser args) { try { Repository.Delete(args.ToDalUser()); } catch (ArgumentNullException exception) { if (LoggerSwitch.Enabled) { Logger.Error(exception.Message); } throw exception; } }
/// <summary> /// Delete user /// </summary> /// <param name="user">User</param> public async Task Delete(BllUser user) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (await context.UserStore.IsExistingUserAsync(user.Login)) { await context.UserStore.DeleteAsync(user.ToDalUser()); } else { throw new NotExistingUserException(nameof(user)); } }
public bool RegisterUser(BllUser newUser) { newUser.RegisrationDate = DateTime.Now; newUser.Role = new BllRole() { Id = (int)RoleEnum.User }; newUser.HashedPassword = Hash(newUser.Password); try { userRepository.Add(newUser.ToDalUser()); return(userRepository.IsExists(u => (u.Login == newUser.Login))); } catch (InvalidOperationException e) { logger.Warn(e.Message); throw; } }
public void DeleteUser(BllUser user) { try { _userRepository.Delete(user.ToDalUser()); _unitOfWork.Commit(); } catch (ArgumentNullException e) { _logger.Error(e.Message); throw; } catch (DbException e) { _logger.Error(e.Message); throw; } catch (Exception e) { _logger.Error(e.Message); throw; } }
protected override void DeleteUser(BllUser user) { if (ReferenceEquals(user, null)) { throw new ArgumentNullException(); } try { Repository.Delete(user.ToDalUser()); } catch (ArgumentNullException exception) { if (LoggerSwitch.Enabled) { Logger.Error(exception.Message); } throw exception; } OnUserDeleted(this, user); }
protected override int AddUser(BllUser user) { if (ReferenceEquals(user, null)) { throw new ArgumentNullException(); } try { Repository.Add(user.ToDalUser()); } catch (ArgumentException exception) { if (LoggerSwitch.Enabled) { Logger.Error(exception.Message); } throw exception; } OnUserAdded(this, user); return(user.Id); }
public void DeleteUser(BllUser user) { userRepository.Delete(user.ToDalUser()); uow.Commit(); }
public void CreateUser(BllUser user) { userRepository.Create(user.ToDalUser()); uow.Commit(); }
public void UpdateUser(BllUser user) { uow.Users.Update(user.ToDalUser()); uow.Commit(); }
public void CreateUser(BllUser user) { userRepository.Insert(user.ToDalUser()); }
/// <summary> /// create user entity /// </summary> /// <param name="bllUser">user entity on Bll</param> /// <param name="roleId">role identifier which user will have after creating</param> public void CreateUser(BllUser bllUser, int roleId) { userRepository.CreateUser(bllUser.ToDalUser(), roleId); uow.Commit(); }
/// <summary> /// update data about user in database /// </summary> /// <param name="user">user with new data</param> public void Update(BllUser user) { userRepository.Update(user.ToDalUser()); uow.Commit(); }
/// <summary> /// Creates a user /// </summary> /// <param name="entity">User </param> /// <param name="roleId">Roles id </param> public void Create(BllUser entity, int roleId) { userRepository.Create(entity.ToDalUser(), roleId); unitOfWork.Commit(); }
/// <summary> /// Removes the user /// </summary> /// <param name="entity">User </param> public void Delete(BllUser entity) { userRepository.Delete(entity.ToDalUser()); DeleteUserResults(entity.Id); unitOfWork.Commit(); }
/// <summary> /// Updates user data /// </summary> /// <param name="entity">User </param> public void Update(BllUser entity) { userRepository.Update(entity.ToDalUser()); unitOfWork.Commit(); }