Пример #1
0
        // POST api/SalesBillCategory
        public HttpResponseMessage PostSalesBillCategory(SalesBillCategory salesbillcategory)
        {
            if (ModelState.IsValid)
            {
                //db.SalesBillCategories.Add(salesbillcategory);
                salesbillcategory.InsertBy = loginUser.UserID;
                db.Entry(salesbillcategory).State = salesbillcategory.SalesBillCategoryID == 0 ?
                EntityState.Added : EntityState.Modified;
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, salesbillcategory);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = salesbillcategory.SalesBillCategoryID }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Пример #2
0
        // PUT api/SalesBillCategory/5
        public HttpResponseMessage PutSalesBillCategory(long id, SalesBillCategory salesbillcategory)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != salesbillcategory.SalesBillCategoryID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }