public User GetById(int id) { var userDTO = _userContext.Select(id); if (userDTO != null) { return(UserMapper.ConvertDTOToUser(userDTO)); } return(null); }
public User InsertUser(User user) { var resultValidator = new UserValidator().Validate(user); if (!resultValidator.IsValid) { _helper.ValidatorHandler(resultValidator); } user.Password = _authenticationService.GetHash(user.Password); var userDTO = UserMapper.ConvertUserToDTO(user); if (_userContext.Insert(userDTO) == 1) { return(UserMapper.ConvertDTOToUser(_userContext.SelectAll().Where(w => w.Username == userDTO.Username).FirstOrDefault())); } return(null); }
public User UpdateUser(int id, User user) { var oldUser = _userContext.Select(id); if (oldUser == null) { return(null); } var resultValidator = new UserValidator().Validate(user); if (!resultValidator.IsValid) { _helper.ValidatorHandler(resultValidator); } if (oldUser.Password != user.Password) { oldUser.Password = _authenticationService.GetHash(user.Password); } oldUser.Document = user.Document; oldUser.Email = user.Email; oldUser.Name = user.Name; _userContext.Update(oldUser); return(UserMapper.ConvertDTOToUser(oldUser)); }