public IActionResult PartiallyUpdateDay(int weekId, int id, [FromBody] JsonPatchDocument <DayForUpdateDto> patchDoc) { var week = WeeksDataStore.Current.Weeks .FirstOrDefault(w => w.Id == weekId); if (week == null) { return(NotFound()); } var dayFromStore = week.Days .FirstOrDefault(d => d.Id == id); if (dayFromStore == null) { return(NotFound()); } var dayToPatch = new DayForUpdateDto() { Date = dayFromStore.Date, WeekDay = dayFromStore.WeekDay }; patchDoc.ApplyTo(dayToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!TryValidateModel(dayToPatch)) { return(BadRequest(ModelState)); } dayFromStore.Date = dayToPatch.Date; dayFromStore.WeekDay = dayToPatch.WeekDay; return(NoContent()); }
public IActionResult UpdateDay(int weekId, int id, [FromBody] DayForUpdateDto day) { var week = WeeksDataStore.Current.Weeks .FirstOrDefault(w => w.Id == weekId); if (week == null) { return(NotFound()); } var dayFromStore = week.Days .FirstOrDefault(d => d.Id == id); if (day == null) { return(NotFound()); } dayFromStore.Date = day.Date; dayFromStore.WeekDay = day.WeekDay; return(NoContent()); }