public int addNewProduct(Product newProduct) { _dbContext.Products.Add(newProduct); _dbContext.SaveChanges(); System.Console.WriteLine("newproduct id:" + newProduct.ID); return(newProduct.ID); }
public void Update(Product product) { var productFromdb = _gMartDbContext.Products.FirstOrDefault(p => p.ID == product.ID); if (productFromdb != null) { productFromdb.Product_Name = product.Product_Name; productFromdb.Product_Price = product.Product_Price; productFromdb.Product_Type = product.Product_Type; productFromdb.Product_Image = product.Product_Image; _gMartDbContext.SaveChanges(); } }
public List <int> AddProducts(List <Product> newProductsList) { List <int> newProductsIDList = new List <int>(); try { foreach (Product product in newProductsList) { dbContext.Products.Add(product); newProductsIDList.Add(product.ID); } dbContext.SaveChanges(); } catch (Exception e) { dbContext = null; Console.WriteLine("Type:" + e.GetType().ToString() + " Message:" + e.Message); } return(newProductsIDList); }
public void SaveDb() { _gMartDbContext.SaveChanges(); }