Esempio n. 1
0
        public HttpResponseMessage Post([FromBody] Product product)
        {
            var prod = new NHateoas.Sample.Models.EntityFramework.DbProduct(product);

            _dbContext.Products.Add(prod);
            _dbContext.SaveChanges();
            return(Request.CreateResponse <Product>(HttpStatusCode.Created, prod));
        }
Esempio n. 2
0
        public void Put(int id, [FromBody] Product product)
        {
            var prod = _dbContext.Products.FirstOrDefault(p => p.Id == product.Id);

            if (prod == null)
            {
                Request.CreateResponse(HttpStatusCode.NotFound);
                return;
            }
            prod.Name  = product.Name ?? prod.Name;
            prod.Price = product.Price;
            _dbContext.SaveChanges();
        }