public long AddNewUser(UserCreateEditModel modelParam) { // TODO: need refactor after changes related to Code First db ValidateDomain(modelParam.Email); var user = _mapper.Map <User>(modelParam); var entry = _userRepository.GetEntry(user); if (entry != null) { if (entry.Email == user.Email) { _actionContext.SetModelError("email", "Email is busy"); } if (entry.Phone == user.Phone) { _actionContext.SetModelError("phone", "Phone is busy"); } } _actionContext.ThrowIfModelInvalid(); user.Roles.Add(_roleRepository.GetDefault()); user.IsWaitingConfirmation = true; user = _userRepository.Add(user); _inviteService.InviteUser(user); return(user.Id); }
public long UpdateUser(UserCreateEditModel modelParam) { // TODO: need refactor after changes related to Code First db ValidateDomain(modelParam.Email); var user = _mapper.Map <User>(modelParam); if (!_userRepository.IsExists(new User { Id = user.Id })) { throw new UserNotFoundException(); } var entry = _userRepository.GetEntry(new User { Email = user.Email }); if (entry != null && entry.Id != user.Id) { _actionContext.SetModelError("email", "Email is busy"); } entry = _userRepository.GetEntry(new User { Phone = user.Phone }); if (entry != null && entry.Id != user.Id) { _actionContext.SetModelError("phone", "Phone is busy"); } _actionContext.ThrowIfModelInvalid(); user = _userRepository.Update(user); return(user.Id); }
public IHttpActionResult UpdateUser(UserCreateEditModel modelParam) { return(Ok(_userService.UpdateUser(modelParam))); }
public IHttpActionResult AddNewUser(UserCreateEditModel modelParam) { var result = _userService.AddNewUser(modelParam); return(Ok(result)); }