public static void createOrder() { Console.WriteLine("Whats your Name? Please enter your full name."); Console.WriteLine("WARNING: you must be registered in our database to make an order!"); Console.WriteLine(""); var userFullName = Console.ReadLine(); Console.WriteLine("Select a location you would like to order from"); storeRepo.getStores(); var userlocation = Console.ReadLine(); Console.WriteLine("What would you like to order?"); OrderItemRepo.getOrderItems(); var orderChoice = Console.ReadLine(); var newOrder = new CustomerOrder { CustomerName = userFullName, LocationName = userlocation, ProductName = orderChoice, }; var context = new projectZeroContext(Options); context.Add(newOrder); context.SaveChanges(); Console.WriteLine("Order Recieved"); }
public void AddCustomer(CustomerModel customer) { //instantiate a customer model instance and map it to db entity? //add logic that sets the user input equal to the values of CustomerModel customer //var maxid = _projectZeroContext.Customer.Max(c => c.CustomerId); var newdbcustomer = new Customer() { FirstName = customer.FirstName, LastName = customer.LastName }; _projectZeroContext.Add(newdbcustomer); _projectZeroContext.SaveChanges(); }
public void AddOrder(CustomerOrderModel neworder) { //create new instance of custorder entity and map its values to new order var newdbcustomerorder = new CustomerOrder() { CustomerName = neworder.CustomerName, AmountPurchased = neworder.AmountPurchased, OrderId = neworder.OrderId, ProductId = neworder.ProductId }; _projectZeroContext.Add(newdbcustomerorder); _projectZeroContext.SaveChanges(); }
public static void addCustomer() { while (true) { try { Console.WriteLine("Whats your Name? Please enter your full name."); var userFullName = Console.ReadLine(); //Console.WriteLine("What's your lastname?"); //var userLastName = Console.ReadLine(); var newCustomer = new Customer { FullName = userFullName, //LastName = userLastName, }; var context = new projectZeroContext(Options); //Input validation if (userFullName.Length == 0) { throw new Exception("the name must not be empty"); } else { context.Add(newCustomer); context.SaveChanges(); break; } } catch (FormatException e) { Console.WriteLine("Please enter a name"); continue; } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } }