public void AddUser(UserDTOM userModel) { UserHelper.ValidateUserEmptyString(userModel); var user = UserMapper.UserModelToUser(userModel); _userRepo.Insert(user); }
public void UpdateUser(UserDTOM userModel) { var userCheck = _userRepo.GetById(userModel.Id); UserHelper.ValidateUserById(userCheck.Id); UserHelper.ValidateUserEmptyString(userModel); var user = UserMapper.UserModelToUser(userModel); _userRepo.Update(user); }
public static User UserModelToUser(UserDTOM user) { return(new User() { Id = user.Id, FirstName = user.FirstName, LastName = user.Password, UserName = user.UserName, Notes = NoteMapper.NotesModelsToNotes(user.Notes.ToList()) }); }
public static void ValidateUserEmptyString(UserDTOM user) { if (string.IsNullOrEmpty(user.UserName)) { throw new UserException(null, "UserName field is required!"); } if (string.IsNullOrEmpty(user.Password)) { throw new UserException(null, "Password field is required"); } if (user.FirstName.Count() > 50) { throw new UserException(null, "FirstName field can not have more then 50 characters"); } }
public ActionResult Put([FromBody] UserDTOM user) { try { _userService.UpdateUser(user); return(Ok("User updated successfully")); } catch (UserException ex) { Debug.WriteLine($"User id {ex.UserId}, message: {ex.Message}"); return(BadRequest(ex.Message)); } catch (Exception ex) { Debug.WriteLine($"ERROR: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }