public async Task DecreaseInventory(string productName, string storeName, int purchasedAmount) { var curInventory = await dbContext.Inventories .Include(x => x.Store) .Include(x => x.Products) .Where(i => i.Store.StoreName == storeName) .Where(p => p.Products.ProductName == productName).FirstOrDefaultAsync(); curInventory.ProductQuantity -= purchasedAmount; dbContext.SaveChangesAsync(); }
public async Task AddCustomerAsync(SleepingSelkieBusinessLogic.BusinessModels.Customer customer) { var custStore = dbContext.Stores .Where(c => c.StoreName == customer.StoreName).FirstOrDefault(); var cust = new DataModels.Customer { FirstName = customer.FirstName, LastName = customer.LastName, Store = custStore, CustomerID = customer.PhoneNumber, }; if (await dbContext.Customers.AnyAsync(c => c.FirstName == cust.FirstName && c.LastName == cust.LastName)) { throw new InvalidOperationException("Customer Already exists"); } dbContext.Add(cust); await dbContext.SaveChangesAsync(); }
public async Task AddOrdersAsync(SleepingSelkieBusinessLogic.BusinessModels.Orders order) { var newOrder = new DataModels.Orders { Customer = dbContext.Customers .Where(x => x.CustomerID == order.CustomerID).FirstOrDefault(), Store = dbContext.Stores .Where(x => x.StoreName == order.StoreName).FirstOrDefault(), ManaPotionsBought = order.ManaPotionsBought, StaminaPotionsBought = order.StaminaPotionsBought, HealthPotionsBought = order.HealthPotionsBought, ClericsTalismanBought = order.ClericsTalismanBought, MagicWandsBought = order.MagicWandsBought, Date = order.Date, }; dbContext.Add(newOrder); await dbContext.SaveChangesAsync(); }