/// <summary> /// Gets the information of a business logic store given an orderID that it came from and a database context /// </summary> /// <param name="orderID"></param> /// <returns></returns> public BusinessLogic.Objects.Store GetStoreInformationFromOrderNumber(int orderID) { BusinessLogic.Objects.Store BLStore = new BusinessLogic.Objects.Store(); try { foreach (Entities.OrderProduct CTXOrdProd in _context.OrderProduct) { if (CTXOrdProd.OrderId == orderID) { BLStore.storeNumber = CTXOrdProd.StoreNumber; } } foreach (Entities.Store CTXStore in _context.Store) { if (CTXStore.StoreNumber == BLStore.storeNumber) { BLStore = ParseHandler.ContextStoreToLogicStore(CTXStore); } } return(BLStore); } catch (Exception e) { Console.WriteLine("Unable to get store information from order: " + e.Message); return(null); } }
/// <summary> /// Inputs an order into the Order table. Does NOT input products. /// </summary> /// <param name="BLOrder"></param> /// <param name="context"></param> public void InputOrder(Order BLOrder, StoreApplicationContext context) { try { context.Orders.Add(ParseHandler.LogicOrderToContextOrder(BLOrder)); context.SaveChanges(); } catch (Microsoft.EntityFrameworkCore.DbUpdateException e) { Console.WriteLine("Something went wrong inputting order: " + e); } }
/// <summary> /// Adds new customer data to the Customer database table given a Business Logic customer object and a database context /// </summary> /// <param name="BLCustomer"></param> /// <param name="context"></param> public void AddNewCustomerData(StoreApp.BusinessLogic.Objects.Customer BLCustomer, StoreApplicationContext context) { //Some code to input customer data to the DB try { context.Customer.Add(ParseHandler.LogicCustomerToContextCustomer(BLCustomer)); context.SaveChanges(); } catch (Exception e) { Console.WriteLine("Failed to put the customer into the database: " + e.Message); } }
/// <summary> /// Inputs the order products into the OrderProduct table under an order ID given a Business Logic Order, an order ID, and a database context /// </summary> /// <param name="BLOrder"></param> /// <param name="orderID"></param> /// <param name="context"></param> public void InputOrderProduct(BusinessLogic.Objects.Order BLOrder, int orderID, StoreApplicationContext context) { try { foreach (BusinessLogic.Objects.Product BLProd in BLOrder.customerProductList) { context.OrderProduct.Add(ParseHandler.LogicProductToContextOrderProduct(BLOrder, orderID, BLProd)); } context.SaveChanges(); } catch (Exception e) { Console.WriteLine("Something went wrong inputting the OrderProduct for the Order: " + e.Message); return; } }
/// <summary> /// Given a manager ID and a database context, returns manager data into a BusinessLibrary manager object /// </summary> /// <param name="managerID"></param> /// <returns></returns> public BusinessLogic.Objects.Manager GetManagerDataFromID(int managerID) { try { foreach (StoreApp.DataLibrary.Entities.Manager man in _context.Manager) { if (man.ManagerId == managerID) { return(ParseHandler.ContextManagerToLogicManager(man)); } } return(null); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
public List <Order> GetListOfOrdersFromStoreNumber(int storeNumber) { List <BusinessLogic.Objects.Order> BLListOrders = new List <Order>(); foreach (Entities.Orders CTXOrder in _context.Orders) { BLListOrders.Add(ParseHandler.ContextOrderToLogicOrder(CTXOrder)); } foreach (BusinessLogic.Objects.Order BLOrder in BLListOrders) { foreach (Entities.OrderProduct CTXOrdProd in _context.OrderProduct) { if (BLOrder.orderID == CTXOrdProd.OrderId) { BLOrder.customerProductList.Add(ParseHandler.ContextOrderProductToLogicProduct(CTXOrdProd)); } } } return(BLListOrders); }
/// <summary> /// Gets a business logic version of a store given a store number and a Database context /// </summary> /// <param name="storeNum"></param> /// <returns></returns> public BusinessLogic.Objects.Store GetStoreFromStoreNumber(int storeNum) { BusinessLogic.Objects.Store BLStore = new BusinessLogic.Objects.Store(); try { foreach (StoreApp.DataLibrary.Entities.Store storeLoc in _context.Store) { if (storeLoc.StoreNumber == storeNum) { BLStore = ParseHandler.ContextStoreToLogicStore(storeLoc); } } return(BLStore); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
/// <summary> /// Gets a list of customer data using an inputted customerID and a Database context /// </summary> /// <param name="customerID"></param> /// <returns></returns> public StoreApp.BusinessLogic.Objects.Customer GetCustomerDataFromID(int customerID) { //Some code to retrieve a list of customer data try { foreach (Entities.Customer cust in _context.Customer) { if (cust.CustomerId == customerID) { return(ParseHandler.ContextCustomerToLogicCustomer(cust)); } } return(null); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
/// <summary> /// Gets a list of Business Logic orders under a valid customer ID and a database context /// </summary> /// <param name="custID"></param> /// <returns></returns> public List <StoreApp.BusinessLogic.Objects.Order> GetListOfOrdersByCustomerID(int custID) { List <Order> listToBeReturned = new List <Order>(); try { foreach (Entities.Orders CTXOrder in _context.Orders) { if (CTXOrder.CustomerId == custID) { listToBeReturned.Add(ParseHandler.ContextOrderToLogicOrder(CTXOrder)); } } return(listToBeReturned); } catch (Exception e) { Console.WriteLine("Operation failed: " + e.Message); return(null); } }
/// <summary> /// Gets the inventory of a store given a store number and a database context /// </summary> /// <param name="storeNumber"></param> /// <returns></returns> public Inventory GetStoreInventoryByStoreNumber(int storeNumber) { Inventory BLInventory = new Inventory(); BusinessLogic.Objects.Product BLProduct = new BusinessLogic.Objects.Product(); try { foreach (Entities.InventoryProduct prod in _context.InventoryProduct) { if (prod.StoreNumber == storeNumber) { BLProduct = ParseHandler.ContextInventoryProductToLogicProduct(prod); BLInventory.productData.Add(BLProduct); BLProduct = new BusinessLogic.Objects.Product(); } else { } } foreach (BusinessLogic.Objects.Product prod in BLInventory.productData) { foreach (Entities.Product entProd in _context.Product) { if (prod.productTypeID == entProd.ProductTypeId) { prod.name = entProd.ProductName; } } } return(BLInventory); } catch (Exception e) { Console.WriteLine("Unable to get the list of store inventory items: " + e.Message); return(null); } }
/// <summary> /// Gets a list of BusinessLogic products using a BusinessLogic Order and a database context /// </summary> /// <param name="BLOrder"></param> /// <returns></returns> public List <BusinessLogic.Objects.Product> GetListOrderProductByOrderID(Order BLOrder) { List <BusinessLogic.Objects.Product> BLProdList = new List <BusinessLogic.Objects.Product>(); foreach (Entities.OrderProduct CTXOrdProd in _context.OrderProduct) { if (CTXOrdProd.OrderId == BLOrder.orderID) { BLProdList.Add(ParseHandler.ContextOrderProductToLogicProduct(CTXOrdProd)); } } foreach (BusinessLogic.Objects.Product BLProd in BLProdList) { foreach (Entities.Product CTXProd in _context.Product) { //If the product in the list is equal to a product ID on the product table, parse to fill name if (BLProd.productTypeID == CTXProd.ProductTypeId) { BLProd.name = CTXProd.ProductName; } } } return(BLProdList); }