public IEnumerable <Product> GetProducts() { using (var productContext = new ProductCatalogContext()) { return(productContext.Products.ToList()); } }
public List <Product> GetById(string id) { using (var productContext = new ProductCatalogContext()) { return(productContext.Products.Where(x => x.productId == id).ToList()); } }
public bool Post(Product product) { using (var productContext = new ProductCatalogContext()) { productContext.Products.Add(product); productContext.SaveChanges(); return(true); } }
public bool Update(Product product) { using (var productContext = new ProductCatalogContext()) { productContext.Products.AddOrUpdate(x => x.productId, product); productContext.SaveChanges(); return(true); } }
public bool Remove(string id) { using (var productContext = new ProductCatalogContext()) { Product prod = productContext.Products.Where(x => x.productId == id).SingleOrDefault(); productContext.Products.Remove(prod); productContext.SaveChanges(); return(true); } }