public void Update(UpdateShiftDto dto) { var shift = _shiftRepository.GetById(dto.Id); if (shift != null) { shift.Title = dto.Title; _shiftRepository.Update(shift); } else { try { throw new LogicalException(); } catch (LogicalException ex) { _logger.LogLogicalError (ex, "Shift entity with the id: '{0}', is not available." + " update operation failed.", dto.Id); throw; } } }
public IHttpActionResult Update([FromBody] UpdateShiftDto shift) { if (shift == null) { return(BadRequest()); } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { _shiftService.Update(shift); } catch (LogicalException ex) { return(BadRequest(ex.Message)); } catch { return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE)); } return(Ok()); }
public ActionResult <ShiftDto> UpdateShift(Guid personId, Guid projectId, Guid shiftId, [FromBody] UpdateShiftDto dto) { try { if (!ModelState.IsValid) { return(BadRequest()); } if (!_db.Person.BelongsToUser(personId, HttpContext)) { return(Forbid()); } if (_db.Participation.GetRole(personId, projectId)?.CalendarWrite != true) { return(Forbid()); } if (_db.Participation.GetEligibilityByCategory(personId, projectId, dto.CategoryId)?.ShiftsWrite != true) { return(Forbid()); } var shift = _db.Shift .FindByCondition(x => x.Id == shiftId) .SingleOrDefault(); if (shift == null) { return(BadRequest()); } if (dto.CategoryId != shift.CategoryId) { if (_db.Participation.GetEligibilityByCategory(personId, projectId, shift.CategoryId)?.ShiftsWrite != true) { return(Forbid()); } } shift.CategoryId = dto.CategoryId; shift.Date = dto.Date; shift.Time = dto.Time; shift.Duration = dto.Duration; _db.Shift.Update(shift); _db.Save(); return(Ok(_db.Shift.GetFullShift(_mapper, shiftId, personId))); } catch (Exception e) { _logger.LogError($"ERROR in UpdateShift: {e.Message}"); return(StatusCode(500, "Internal server error")); } }