Beispiel #1
0
        public HttpResponseMessage PostSale(Sale sale)
        {
            if (ModelState.IsValid)
            {
                repo.createSale(sale);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, sale);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = sale.ID }));
                SaleDTO factoredSale = TheFactory.Create(sale);

                return Request.CreateResponse(HttpStatusCode.OK, factoredSale);
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Beispiel #2
0
        public HttpResponseMessage PutSale(int id, Sale sale)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != sale.ID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            repo.putSale(id,sale);

            SaleDTO factoredSale = TheFactory.Create(sale);

            return Request.CreateResponse(HttpStatusCode.OK, factoredSale);
        }