/// <summary> /// Method that adds customers to database /// </summary> /// <param name="c"></param> public void AddCustomer(BL.Customer c) { //Code to add customer to database using var context = GetContext(); Customer cust = ParseCustomer(c); context.Customer.Add(cust); context.SaveChanges(); }
/// <summary> /// Method that converts Business Logic Customer objects to Data Access customer objects (for connecting with database) /// </summary> /// <param name="c"></param> /// <returns>DataAccces Customer object</returns> public Customer ParseCustomer(BL.Customer c) { Customer cust = new Customer() { FirstName = c.FirstName, LastName = c.LastName, Street = c.CustAddress.Street, City = c.CustAddress.City, State = c.CustAddress.State.ToString(), ZipCode = c.CustAddress.Zipcode.ToString() }; return(cust); }
/// <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 DataAccess Customer objects to Business Logic Customer objects (for ineracting with UI) /// </summary> /// <param name="c"></param> /// <returns>BusinessLogic Customer object</returns> public BL.Customer ParseCustomer(Customer c) { BL.Customer cust = new BL.Customer() { FirstName = c.FirstName, LastName = c.LastName, CustAddress = new BL.Address() { Street = c.Street, City = c.City, State = (BL.States)Enum.Parse(typeof(BL.States), c.State, true), Zipcode = int.Parse(c.ZipCode) } }; return(cust); }