Example #1
0
        // POST api/CourseHoles
        public HttpResponseMessage PostCourseHole(CourseHole courseHole)
        {
            if (ModelState.IsValid)
            {
                holeRepository.Create(courseHole);

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

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
Example #2
0
        // PUT api/CourseHoles/5
        public HttpResponseMessage PutCourseHole(int id, CourseHole courseHole)
        {
            if (ModelState.IsValid && id == courseHole.Id)
            {
                try
                {
                    holeRepository.Update(courseHole);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }