public IActionResult Add([FromBody] ShiftDto shift) { var newShift = new Shift { Date = shift.Date, EmployeeId = shift.EmployeeId, ManagerId = shift.ManagerId, WorkFromHome = shift.WorkFromHome, Callout = shift.Callout, Planned = shift.Planned, ShiftLengthId = shift.ShiftLengthId, Email = shift.Email, Phone = shift.Phone, Integrations = shift.Integrations, NonCoverage = shift.NonCoverage }; bool addShift; try { addShift = _repo.AddShift(newShift); } catch (Exception) { return(StatusCode((int)HttpStatusCode.InternalServerError, "Sorry, something went wrong. Please try again later.")); } return(addShift ? StatusCode((int)HttpStatusCode.Created, "Shift has been added!") : StatusCode((int)HttpStatusCode.InternalServerError, "Sorry, something went wrong. Please try again later.")); }
public IActionResult EditShift(int id, [FromBody] ShiftDto shift) { var shiftToEdit = new Shift { ShiftId = id, Date = shift.Date, EmployeeId = shift.EmployeeId, ManagerId = shift.ManagerId, WorkFromHome = shift.WorkFromHome, Callout = shift.Callout, Planned = shift.Planned, ShiftLengthId = shift.ShiftLengthId, Email = shift.Email, Phone = shift.Phone, Integrations = shift.Integrations, NonCoverage = shift.NonCoverage }; var editShift = new ShiftModifier(_repo).EditShift(shiftToEdit); switch (editShift) { case StatusCodes.Success: return(StatusCode((int)HttpStatusCode.OK, "The shift has been edited!")); case StatusCodes.NotFound: return(StatusCode((int)HttpStatusCode.NotFound, "There does not appear to be a shift associated with that day.")); case StatusCodes.Unsuccessful: return(StatusCode((int)HttpStatusCode.InternalServerError, "Sorry, something went wrong. Please try again later.")); default: return(StatusCode((int)HttpStatusCode.InternalServerError, "Sorry, something went wrong. Please try again later.")); } }