public List <Product> GetProducts() { using (var shopEntities = new ShopEntities()) { return(shopEntities.Products.ToList()); } }
public void UpdateProduct(string name, decimal price, string currency, int stock) { using (var shopEntities = new ShopEntities()) { var existingProduct = shopEntities.Products.FirstOrDefault(x => x.Name == name); if (existingProduct != null) { existingProduct.Stock += stock; } else { shopEntities.Products.Add(new Product() { Name = name, Price = price, Currency = currency, Stock = stock }); } shopEntities.SaveChanges(); } }