/// <summary> /// Create Client User /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <bool> CreateUser(CreateUserModel model) { if (!ValidateUtils.IsMail(model.Email)) { throw new FormatException("Email address invalid"); } if (model.Password != model.Repassword) { throw new FormatException("Wrong Repass"); } var query = _userRepository.GetManyAsNoTracking(x => x.Email.Equals(model.Email)); if (query.ToList().Count > 0) { throw new FormatException("Email is existed"); } var user = _userRepository.Insert(new TblUser { UserId = Guid.NewGuid(), Email = model.Email, Name = model.UserName, Password = model.Password, Phone = model.Phone, Role = false }); await _unitOfWork.CommitAsync(); return(true); }
/// <summary> /// Creates the user account. /// </summary> /// <param name="model">The model.</param> /// <param name="userProfileId">The user profile identifier.</param> /// <returns></returns> /// <exception cref="FormatException"> /// Email invalid /// or /// Password invalid /// </exception> public async Task <bool> CreateUserAccount(UserAccountCreateModel model, Guid userProfileId) { if (!ValidateUtils.IsMail(model.Email)) { throw new FormatException("Email invalid"); } if (model.Password.Length < 8) { throw new FormatException("Password invalid"); } var passwordSalt = Guid.NewGuid(); var data = HashingUtils.GetHashData(model.Password + passwordSalt); _userAccountRepository.Insert(new UserAccount { Email = model.Email, PasswordHash = data.DataHashed, PasswordHashAlgorithm = data.HashType, UserProfileId = userProfileId, PasswordSalt = passwordSalt, UserAccountStatusCode = RefUserAccountStatusCode.Guest }); await _unitOfWork.CommitAsync(); return(true); }
/// <summary> /// Creates the user profile. /// </summary> /// <param name="profileModel">The profile model.</param> /// <param name="accountModel">The account model.</param> /// <returns></returns> /// <exception cref="FormatException"> /// Email address invalid /// or /// Phone number invalid /// or /// Email existed /// </exception> public async Task <bool> CreateUserProfile(UserRegisterModel profileModel , UserAccountCreateModel accountModel) { if (!ValidateUtils.IsMail(profileModel.Email)) { throw new FormatException("Email address invalid"); } var query = _userProfileRepository.GetManyAsNoTracking(x => x.Email.Equals(profileModel.Email)); if (query.ToList().Count != 0) { throw new FormatException("Email existed"); } var userProfile = _userProfileRepository.Insert(new UserProfile { Email = profileModel.Email, FirstName = profileModel.FirstName, LastName = profileModel.LastName, Phone = profileModel.Phone, Address = profileModel.Address }); return(await _userAccountService.CreateUserAccount(accountModel, userProfile.Entity.UserProfileId)); }
/// <summary> /// Updates the email. /// </summary> /// <param name="id">The identifier.</param> /// <param name="email">The email.</param> /// <returns></returns> /// <exception cref="EntityNotFoundException">User id {id} not found</exception> /// <exception cref="FormatException">Email is wrong format</exception> public async Task <UserProfile> UpdateEmail(Guid id, string email) { var user = _userProfileRepository.GetById(id); if (user == null) { throw new EntityNotFoundException($"User id {id} not found"); } if (!ValidateUtils.IsMail(email)) { throw new FormatException($"Email is wrong format"); } user.Email = email; _userProfileRepository.Update(user); await _unitOfWork.CommitAsync(); return(user); }
/// <summary> /// Update User /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <bool> UpdateUser(UpdateUserModel model) { var query = _userRepository.GetById(model.UserId); if (query == null) { throw new FormatException("User Not Found"); } if (!ValidateUtils.IsMail(model.Email)) { throw new FormatException("Email address invalid"); } query.Name = model.UserName; query.Password = model.Password; query.Phone = model.Phone; query.Email = model.Email; _userRepository.Update(query); await _unitOfWork.CommitAsync(); return(true); }