public void AddNewCustomerDB() { DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>() .UseSqlServer(secret.ConnectionString).Options; var context = new CupCakeShopContext(options); Customer newCustomer = new Customer(); while (true) { Console.Clear(); Console.WriteLine("Cup Cake Shop\n"); Console.WriteLine("Enter Customer First and Last Name:"); Console.WriteLine("(or 1 to Return to Menu)\n"); string customerName = Console.ReadLine(); string[] fullName = customerName.Split(' '); if (fullName[0].ToLower() == "1") //main menu { return; } else if (string.IsNullOrEmpty(customerName) || fullName.Length != 2) //validation { Console.WriteLine("Invalid Name\n"); Console.WriteLine("Press a key to continue."); Console.ReadKey(); } else { newCustomer.FirstName = fullName[0]; //add newCustomer.LastName = fullName[1]; break; } } context.Customer.Add(newCustomer); context.SaveChanges(); Console.Clear(); Console.WriteLine("Cup Cake Shop\n"); Console.WriteLine($"{newCustomer.FirstName} {newCustomer.LastName} added to the system.\n"); //show output Console.WriteLine("Press a key to continue: "); Console.ReadKey(); }
public void PlaceNewOrderDB(int customerId, int cupId, int cupLocationId, int cupQuantId, decimal orderTotal) { DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>() .UseSqlServer(secret.ConnectionString).Options; var context = new CupCakeShopContext(options); Orders newOrder = new Orders(); newOrder.CustomerId = customerId; newOrder.ProductId = cupId; newOrder.LocationId = cupLocationId; newOrder.Quantity = cupQuantId; newOrder.OrderTotal = orderTotal; DateTime now = DateTime.Now; newOrder.OrderTime = now; context.Orders.Add(newOrder); context.SaveChanges(); }