Esempio n. 1
0
        // POST api/Holes
        public HttpResponseMessage PostHole(Hole hole)
        {
            if (ModelState.IsValid)
            {
                holeRepository.Create(hole);

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

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
Esempio n. 2
0
        // PUT api/Holes/5
        public HttpResponseMessage PutHole(int id, Hole hole)
        {
            if (ModelState.IsValid && id == hole.Id)
            {
                try
                {
                    holeRepository.Update(hole);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }