/// <summary> /// Method that prints order details after placing an order /// </summary> /// <param name="o"></param> public void PrintOrderDetails(BL.Orders o) { Console.WriteLine("Order placed!"); Console.WriteLine($"Customer Name: {o.Cust.FirstName} {o.Cust.LastName} \nBranchname: {o.Stor.BranchName}"); foreach (BL.Inventory i in o.CustOrder) { Console.WriteLine($"Product: {i.Prod.Name} \n Price (per unit): {i.Prod.Price} \n Quantity: {i.Stock}"); } Console.WriteLine($"Order Total: {o.Total}"); }
/// <summary> /// Method that converts Data Access Order objects to Business Logic Order Object for UI interaction /// </summary> /// <param name="o"></param> /// <returns>Business Logic Order</returns> public BL.Orders ParseOrder(Orders o) { using var context = GetContext(); CustomerHandler ch = new CustomerHandler(); LocationHandler lh = new LocationHandler(); BL.Orders ord = new BL.Orders() { Date = o.OrderDate, Cust = ch.ParseCustomer(context.Customer.Single(c => c.CustId == o.CustId)), Stor = lh.ParseLocation(context.Location.Single(l => l.LocationId == o.LocationId)), CustOrder = ParseCustOrder(context.CustOrder.Where(c => c.OrderId == o.OrderId).ToList()), Total = o.Total, }; return(ord); }
/// <summary> /// Method that adds order a customer placed on the DB /// </summary> /// <param name="o"></param> public void AddOrder(BL.Orders o) { using var context = GetContext(); CustomerHandler ch = new CustomerHandler(); LocationHandler lh = new LocationHandler(); Orders order = new Orders() { Cust = context.Customer.Single(c => c.FirstName == o.Cust.FirstName && c.LastName == o.Cust.LastName && c.City == o.Cust.CustAddress.City), Location = context.Location.Single(l => l.BranchName == o.Stor.BranchName), CustOrder = ParseCustOrder(o.CustOrder), Total = o.Total, OrderDate = DateTime.Now }; context.Orders.Add(order); context.SaveChanges(); }