public int AddProduct(string name, decimal buyingPrice, decimal sellingPrice) { Product product = new Product() { Name = name, AvailableQuantity = 0, SellingPrice = sellingPrice, BuyingPrice = buyingPrice }; try { context.Products.Add(product); return context.SaveChanges(); } catch (InvalidOperationException) { throw new InvalidOperationException("Não foi possível adicionar o produto."); } finally { RefreshItems(); } }
public int EditProduct(Product product) { try { context.Entry<Product>(product).State = System.Data.Entity.EntityState.Modified; return context.SaveChanges(); } catch (InvalidOperationException) { throw new InvalidOperationException("Não foi possível editar o produto."); } finally { RefreshItems(); } }