/// <summary> /// Saves all the inventory to the database /// </summary> /// <param name="inventory">The inventory stored as a dictionary with LocationName:List<Product> as its Key/Value</param> public void saveAllInventory(Dictionary <string, List <lib.Product> > inventory) { try { foreach (var dataProduct in _context.Inventories.Include(i => i.Location).Include(i => i.Product)) { dataProduct.Amount = inventory[dataProduct.Location.Name] .FirstOrDefault(prod => prod.ProductId == dataProduct.ProductId) .Amount; _context.Update(dataProduct); } _context.SaveChanges(); } catch (Exception) { Console.WriteLine("Error creating new orders"); } }
/// <summary> /// Saves the customer to the database /// </summary> /// <param name="customer">The customer with changes to be saved</param> public void saveCustomer(lib.Customer customer) { try { using var context = new StoreDBContext(_options); var dataCustomer = context.Customers.Where(c => c.CustomerId == customer.CustomerId).FirstOrDefault(); dataCustomer.Balance = customer.Balance; context.Update(dataCustomer); context.SaveChanges(); } catch (Exception) { Console.WriteLine("Error saving customer's."); } }