Ejemplo n.º 1
0
        // POST api/Accomodation
        public HttpResponseMessage PostAccomodation(Accomodation accomodation)
        {
            if (ModelState.IsValid)
            {
                db.Accomodations.Add(accomodation);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, accomodation);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = accomodation.AccomodationId }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Ejemplo n.º 2
0
        // PUT api/Accomodation/5
        public HttpResponseMessage PutAccomodation(Guid id, Accomodation accomodation)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != accomodation.AccomodationId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(accomodation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }