public IActionResult UpdateShift(int id, [FromBody] ShiftForUpdateDto shift) { try { if (shift == null) { _logger.LogError("shift object sent from client is null."); return(BadRequest("shift object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid shift object sent from client."); return(BadRequest("Invalid model object")); } var shiftEntity = _repository.Shift.GetShiftById(id); if (shiftEntity == null) { _logger.LogError($"shift with id: {id}, hasn't been found in db."); return(NotFound()); } _mapper.Map(shift, shiftEntity); _repository.Shift.UpdateShift(shiftEntity); _repository.Save(); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateShift action: {ex.InnerException.Message}"); return(StatusCode(500, "Internal server error")); } }
public ActionResult UpdateShift(int shiftId, ShiftForUpdateDto shift) { var shiftFromRepo = _shiftRepository.GetShift(shiftId); if (shiftFromRepo == null) { return(NotFound()); } _mapper.Map(shift, shiftFromRepo); _shiftRepository.UpdateShift(shiftFromRepo); //mapper modify the entity, so update isn't needed in this implementation _shiftRepository.Save(); return(NoContent()); }