public IActionResult UpdateGender(int id, [FromBody] Gender gender) { try { if (gender.IsEntityNull()) { return(BadRequest("Gender object is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } Gender dbGender = _genderService.GetGenderById(id); if (dbGender.IsEntityNull()) { _logger.Error($"Gender with id: {id} not found in db"); return(NotFound()); } _genderService.UpdateGender(dbGender, gender); _genderService.Save(); return(NoContent()); } catch (Exception ex) { _logger.Error(ex, "Error in call : api/gender/UpdateGender/" + id, gender); return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error")); } }
public async Task <IActionResult> Put(int id, [FromBody] GenderDTO generoDTO) { var currentGenero = await _genderService.GetGender(id); if (currentGenero == null) { return(NotFound()); } if (id != generoDTO.Id) { return(BadRequest()); } var updateGenero = _mapper.Map <Gender>(generoDTO); updateGenero.Id = id; var result = await _genderService.UpdateGender(updateGenero); if (!result) { return(BadRequest()); } return(NoContent()); }