Exemple #1
0
        // POST api/Courses
        public HttpResponseMessage PostCourse(Course course)
        {
            if (ModelState.IsValid)
            {
                courseRepository.Create(course);

                var response = Request.CreateResponse(HttpStatusCode.Created, course);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = course.Id }));
                return response;
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
Exemple #2
0
        // PUT api/Courses/5
        public HttpResponseMessage PutCourse(int id, Course course)
        {
            if (ModelState.IsValid && id == course.Id)
            {
                try
                {
                    courseRepository.Update(course);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }