public IActionResult CreateShift([FromBody] ShiftForCreationDto shifts) { try { if (shifts == null) { _logger.LogError("shifts object sent from client is null."); return(BadRequest("shifts object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid shifts object sent from client."); return(BadRequest("Invalid model object")); } var shiftEntity = _mapper.Map <Shift>(shifts); _repository.Shift.CreateShift(shiftEntity); _repository.Save(); var createdShiftStatus = _mapper.Map <ShiftDto>(shiftEntity); return(CreatedAtRoute("ShiftById", new { id = createdShiftStatus.ShiftId }, createdShiftStatus)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreateShift action: {ex.InnerException.Message}"); return(StatusCode(500, "Internal server error")); } }
public ActionResult <ShiftDto> Createshift(ShiftForCreationDto shift) { var shiftEntity = _mapper.Map <Shift>(shift); _shiftRepository.AddShift(shiftEntity); _shiftRepository.Save(); var shiftToReturn = _mapper.Map <ShiftDto>(shiftEntity); return(CreatedAtRoute("Getshift", new { shiftId = shiftToReturn.Id }, shiftToReturn)); }