public IHttpActionResult UpdateCourse(int ID, CourseUpdateViewModel courseVM) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.PreconditionFailed); } bool updateSuccessful = _service.UpdateCourse(ID, courseVM); if (!updateSuccessful) { return(NotFound()); } return(Ok()); //Skila líklega Ok(object) eða content(StatusCode.Ok, CourseDTO); }
public IHttpActionResult UpdateCourse(int id, UpdateCourseViewModel editedCourse) { if (!ModelState.IsValid || editedCourse.StartDate.Equals(DateTime.MinValue) || editedCourse.EndDate.Equals(DateTime.MinValue)) { throw new HttpResponseException(HttpStatusCode.PreconditionFailed); } try { CourseDetailsDTO course = _service.UpdateCourse(id, editedCourse); var location = Url.Link("GetCourse", new { id = course.ID }); return(Created(location, course)); } catch (CourseNotFoundException) { throw new HttpResponseException(HttpStatusCode.NotFound); } }
public IHttpActionResult UpdateCourse(int id, [FromBody] UpdateCourseDetailViewModel course) { if (!ModelState.IsValid) { return(BadRequest("Course model not valid!")); } try { return(Ok(_service.UpdateCourse(id, course))); } catch (NotFoundException) { return(NotFound()); } catch (DbException) { return(InternalServerError()); } }
public IHttpActionResult UpdateCourse(int ID, CourseUpdateViewModel courseVM) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.PreconditionFailed); } CourseDTO courseDTO = null; try { courseDTO = _service.UpdateCourse(ID, courseVM); } catch (AppObjectNotFoundException) { return(NotFound()); } return(Ok(courseDTO)); }