public IHttpActionResult Put(int id, [FromBody] UpdateClashException command) { // MUST BE REWORKED! var offsetHours = 6; if (id == 0 || command == null) { return(this.Error().InvalidParameters()); } var clashException = _clashExceptionRepository.Find(id); if (clashException == null) { return(NotFound()); } ClashException.Validation(clashException.StartDate, command.EndDate, command.TimeAndDows); var ValidationPayload = new[] { MapToClashExceptionForValidation(command, clashException) }; var validationResult = ValidateForSave(ValidationPayload); if (!validationResult.Successful) { return(this.Error().BadRequest(ApiError.BadRequest(validationResult.Message))); } MapToClashExceptions(command, ref clashException); _clashExceptionRepository.Add(clashException); _clashExceptionRepository.SaveChanges(); return(Ok(_clashExceptionRepository.GetWithDescriptions(clashException.Id))); }
private ClashException MapToClashExceptionForValidation(UpdateClashException command, ClashException clashException) { return(new ClashException() { Id = clashException.Id, FromType = clashException.FromType, ToType = clashException.ToType, FromValue = clashException.FromValue, ToValue = clashException.ToValue, StartDate = clashException.StartDate, EndDate = command.EndDate, TimeAndDows = command.TimeAndDows, IncludeOrExclude = command.IncludeOrExclude }); }
private void MapToClashExceptions(UpdateClashException command, ref ClashException clashException) { clashException.EndDate = (command.EndDate == null ? (DateTime?)null : command.EndDate.Value.Date); clashException.IncludeOrExclude = command.IncludeOrExclude; clashException.TimeAndDows = command.TimeAndDows; }