public bool DeleteAProduct(int id) { int index = products.FindIndex(p => p.Id == id); if (index >= 0) { products.RemoveAt(index); string rootPath = Path.Combine(webHostingEnvironment.WebRootPath, folder); LocalDataAccess.WriteDataProduct(rootPath, productFile, products); return(true); } return(false); }
public bool AddAProduct(Product newProduct) { int index = products.FindIndex(p => p.Id == newProduct.Id); if (index >= 0) { return(false); } products.Add(newProduct); string rootPath = Path.Combine(webHostingEnvironment.WebRootPath, folder); LocalDataAccess.WriteDataProduct(rootPath, productFile, products); return(true); }
//Method to update database regarding products which has stock property changed private bool UpdateProductList(List <Product> changedProducts) { if (changedProducts.Count > 0) { var updatedProducts = new List <Product>(products); //Make a copy foreach (var product in changedProducts) { int index = updatedProducts.FindIndex(p => p.Id == product.Id); if (index >= 0) { updatedProducts[index] = product; } } LocalDataAccess.WriteDataProduct(rootPath, productFile, updatedProducts); return(true); } return(false); }
public bool UpdateAProduct(int id, Product newProduct) { int index = products.FindIndex(p => p.Id == id); if (index >= 0) { products[index].Name = newProduct.Name; products[index].DateAdded = newProduct.DateAdded; products[index].MfgName = newProduct.MfgName; products[index].MfgDate = newProduct.MfgDate; products[index].ExpiredDate = newProduct.DateAdded; products[index].Type = newProduct.Type; products[index].Stock = newProduct.Stock; string rootPath = Path.Combine(webHostingEnvironment.WebRootPath, folder); LocalDataAccess.WriteDataProduct(rootPath, productFile, products); return(true); } return(false); }