コード例 #1
0
        public IHttpActionResult GetProduct(string id)
        {
            ProductAPI.core.Entities.Product product = db.GetById(id);
            if (product == null)
            {
                return(NotFound());
            }

            return(Ok(product));
        }
コード例 #2
0
        public IHttpActionResult PostProduct(ProductAPI.core.Entities.Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Add(product);

            return(CreatedAtRoute("DefaultApi", new { id = product.ProductID }, product));
        }
コード例 #3
0
        public IHttpActionResult PutProduct(string id, ProductAPI.core.Entities.Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductID)
            {
                return(BadRequest());
            }

            //db.Entry(product).State = EntityState.Modified;
            db.Edit(product);
            return(StatusCode(HttpStatusCode.NoContent));
        }