public void UserResponse(int response) { var optionsBuilder = new DbContextOptionsBuilder <MakeupStoreDbContext>(); optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString); var options = optionsBuilder.Options; using (var dbContext = new MakeupStoreDbContext(options)) { var c = new Store.Library.Customer(); c.FirstName = first; c.LastName = last; c.Email = email; c.AddCustomer(dbContext); if (response == 1) { c.PlaceOrder(dbContext); } if (response == 2) { c.CheckOrderHistory(dbContext); } } }
public void CheckOrderHistory(MakeupStoreDbContext dbContext) { var myHistory = dbContext .OrderHistory .Where(u => u.CustomerId == customerIdNumber) .Include(x => x); Console.WriteLine(myHistory); }
public void AddCustomer(MakeupStoreDbContext dbContext) { var newCustomer = new MakeupStore.DataAccess.Customer { FirstName = firstName, LastName = lastName, Email = email }; dbContext.Customer.Add(newCustomer); dbContext.SaveChanges(); }
//might not be in this class (maybe move to order) public void PlaceOrder(MakeupStoreDbContext dbContext) { var o = new Orders(); string ans = ""; string where = ""; if (defaultStoreLocation != null) { Console.WriteLine($"Would you like to shop at {defaultStoreLocation}?"); ans = Console.ReadLine(); if (ans.Equals("y")) { where = "Arlington"; } else { Console.WriteLine("Enter your preffered store to shop:"); foreach (var loc in dbContext.Locations.Include(l => l.Inventory)) { Console.WriteLine($"{loc.LocationId}. {loc.LocationName}"); } where = Console.ReadLine(); } } else { Console.WriteLine("Enter your preffered store to shop:"); foreach (var loc in dbContext.Locations.Include(l => l.Inventory)) { Console.WriteLine($"{loc.LocationId}. {loc.LocationName}"); } where = Console.ReadLine(); } Console.WriteLine($"Displaying Inventory for {where}:"); foreach (var item in dbContext.InventoryItem.Include(i => i.Inventory)) { Console.WriteLine($"{item.ItemId}. {item.ItemName} Price: ${item.Price}"); } int it = 0; float tot = 0; while (true) { Console.WriteLine("Enter ID to Item you want:"); it = Convert.ToInt32(Console.ReadLine()); foreach (var item in dbContext.InventoryItem.Include(i => i.Inventory)) { if (it == item.ItemId) { tot += item.Price; } } o.LocationName = where; o.ItemId = it; o.OrderTime = DateTime.Now; //dbContext.Database.ExecuteSqlCommand("UPDATE TABLE [dbo].[Inventory] WHERE [LocationId] =="); foreach (var cust in dbContext.Customer.Include(c => c.Orders)) { if (cust.FirstName.Equals(firstName) && cust.LastName.Equals(LastName)) { o.CustomerId = cust.CustomerId; } } dbContext.Add(o); var newOrderHistory = new OrderHistory { OrderId = o.OrderId, CustomerId = o.CustomerId, Total = tot }; try { dbContext.Add(newOrderHistory); dbContext.SaveChanges(); } catch (DbUpdateException e) { Console.WriteLine("Unable yo update thr database!", e); } finally { } Console.WriteLine("Buy another item? (y/n)"); ans = Console.ReadLine(); if (ans.Equals("n")) { break; } } }
} // can use logger for this //additional business rules (limited edition items can only be two per order) public void AddToOrder(MakeupStoreDbContext dbContext) { }