/// <summary> /// Updates the start date and/or end date of a course /// </summary> /// <param name="course">Info about the changes in a course</param> public void UpdateCourse(CourseDetailDTO course) { var toChange = _db.Courses.FirstOrDefault(x => x.ID == course.ID); if(toChange == null) { throw new KeyNotFoundException(); } toChange.StartDate = course.StartDate == null ? toChange.StartDate : course.StartDate; toChange.EndDate = course.EndDate == null ? toChange.EndDate : course.EndDate; _db.SaveChanges(); }
public IHttpActionResult UpdateCourse(int id, [FromBody]UpdateCourseViewModel course) { CourseDetailDTO input = new CourseDetailDTO(); input.ID = id; input.StartDate = course.NewStartDate; input.EndDate = course.NewEndDate; try { _context.UpdateCourse(input); } catch(Exception ex) { if (ex is KeyNotFoundException) return NotFound(); return InternalServerError(); } return StatusCode(HttpStatusCode.NoContent); }