public async Task <IActionResult> Put(Guid userId, [FromBody] UserAddOrUpdateResource value) { if (value == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var user = await _userRepository.GetUserByIdAsync(userId); if (user == null) { return(NotFound()); } _mapper.Map(value, user); if (!await _unitOfWork.CompleteWorkAsync()) { throw new Exception($"Updating user {userId} failed when saving"); } return(NoContent()); }
public async Task <IActionResult> Post([FromBody] UserAddOrUpdateResource user) { if (user == null) { return(BadRequest()); } var userEntity = _mapper.Map <User>(user); _userRepository.AddUser(userEntity); if (await _unitOfWork.CompleteWorkAsync()) { throw new Exception("Error occurred when adding"); } return(CreatedAtAction(nameof(Get), new { userId = userEntity.UserId }, userEntity)); }