public void Post(Product value) { if (ModelState.IsValid) { context.Products.Add(value); context.SaveChanges(); } }
public void PutProduct(int id, Product product) { product.Id = id; var original = _dbContext.Products.Find(product.Id); if (original == null) { return; } _dbContext.Entry(original).CurrentValues.SetValues(product); _dbContext.SaveChanges(); }
public void Put(Product updated) { if (ModelState.IsValid) { var product = (from p in context.Products where p.Id == updated.Id select p).SingleOrDefault(); if (product == null) return; product.PartNumber = updated.PartNumber; product.PartDescription = updated.PartDescription; product.Category = updated.Category; product.Price = updated.Price; context.Entry<Product>(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void PostProduct(Product product) { _dbContext.Products.Add(product); _dbContext.SaveChanges(); }