コード例 #1
0
        // POST api/ProductReceiveDelivery
        public HttpResponseMessage PostProductReceiveDelivery(ProductReceiveDelivery productreceivedelivery)
        {
            if (ModelState.IsValid)
            {
                productreceivedelivery.InsertBy = loginUser.UserID;
                db.ProductReceiveDeliveries.Add(productreceivedelivery);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, productreceivedelivery);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = productreceivedelivery.ProductReceiveDeliveryID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
        // PUT api/ProductReceiveDelivery/5
        public HttpResponseMessage PutProductReceiveDelivery(long id, ProductReceiveDelivery productreceivedelivery)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != productreceivedelivery.ProductReceiveDeliveryID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            productreceivedelivery.UpdateBy = loginUser.UserID;
            db.Entry(productreceivedelivery).State = EntityState.Modified;

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }