示例#1
0
        public IHttpActionResult PatchProduct(int id, [FromUri] ProductPatchVM item)
        {
            Product product = db.Product.Find(id);

            if (product == null)
            {
                return(NotFound());
            }

            product.ProductName = item.ProductName;
            product.Price       = item.Price;

            db.SaveChanges();

            return(Ok(product));
        }
示例#2
0
        public IHttpActionResult PatchProduct(int id, [FromUri] ProductPatchVM product)
        {
            var item = db.Product.Find(id);

            if (item == null)
            {
                return(NotFound());
            }

            if (product.Price.HasValue)
            {
                item.Price = product.Price.Value;
            }
            if (product.Stock.HasValue)
            {
                item.Stock = product.Stock.Value;
            }
            db.SaveChanges();

            return(Ok(item));
        }