Ejemplo n.º 1
0
        public HttpResponseMessage PostCart(Cart cart)
        {
            if (ModelState.IsValid)
            {
                repo.createCart(cart);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, cart);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = cart.ID }));
                CartDTO factoredCart = TheFactory.Create(cart);

                return Request.CreateResponse(HttpStatusCode.OK, factoredCart);

            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage PutCart(int id, Cart cart)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != cart.ID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            repo.putCart(id, cart);
            CartDTO factoredCart = TheFactory.Create(cart);

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