/// <summary> /// Method that gets customer's order history based on their first and last name /// </summary> /// <param name="c"></param> /// <returns></returns> public List <BL.Orders> GetCustomerHistory(BL.Customer c) { //get customer order history using var context = GetContext(); CustomerHandler ch = new CustomerHandler(); List <BL.Orders> output = new List <BL.Orders>(); List <Orders> dbOrd = context.Orders.Where(o => o.Cust.FirstName == c.FirstName && o.Cust.LastName == c.LastName && o.Cust.City == c.CustAddress.City).ToList(); foreach (Orders o in dbOrd) { output.Add(ParseOrder(o)); } return(output); }
/// <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(); }