Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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());
            }
        }
Пример #4
0
        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));
        }