Exemplo n.º 1
0
        /// <summary>
        /// Method runs when creating a new
        /// </summary>
        /// <param name="customer"></param>
        public void CreateCustomerInDb(CustomerClass customer)
        {
            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Create a database customer using info from ConsoleApp Customer
            Customer dbCustomer = new Customer
            {
                Name = customer.Name
            };

            // Add Customer to database and save change
            context.Customers.Add(dbCustomer);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        public Dictionary <string, int> CreateStoreInventory(int storeID)
        {
            // Create empty dictionary to fill in inventory
            Dictionary <string, int> inventory = new Dictionary <string, int>();

            //SortedList<>
            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Get agg inventory items from the database- this is a stores inventory
            var itemsInInventory = context.AggInventories.Where(i => i.StoreId == storeID).ToList();
            // create console inventory with db inventory pieces

            Dictionary <string, int> inv = itemsInInventory.ToDictionary(i => i.Product, i => i.InStock);

            return(inv);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update the inventory in the database after an order is placed
        /// </summary>
        /// <param name="order"></param>
        public void UpdateInventory(IOrder order)
        {
            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Get agg inventory items from the database- this is a stores inventory
            var itemsInInventory = context.AggInventories.Where(i => i.StoreId == order.Location.Id).ToList();

            // Iterate over the items in the order
            foreach (var item in order.Customer.ShoppingCart)
            {
                // Find the item in the list of items that are in stock at that store
                //   then decrement based on the amount ordered
                var currentItem = itemsInInventory.Find(x => x.Product == item.Key);
                currentItem.InStock -= item.Value;
            }
            // Save changes made and send to DB
            context.SaveChanges();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create console app store, from the database. Complete with inventory.
        /// </summary>
        /// <param name="storeID"></param>
        /// <returns></returns>
        public Location CreateStoreWithInventory(int storeID)
        {
            // Create empty dictionary to fill in inventory
            Dictionary <string, int> inventory = new Dictionary <string, int>();

            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Get agg inventory items from the database- this is a stores inventory
            var itemsInInventory = context.AggInventories.Where(i => i.StoreId == storeID).ToList();
            // create console inventory with db inventory pieces
            Dictionary <string, int> inv = itemsInInventory.ToDictionary(i => i.Product, i => i.InStock);
            // Create store From Store DBtable
            var dbStore = context.Stores.Where(s => s.Id == storeID);
            // Create the store in the console. Complete with an inventory
            var appStore = dbStore.Select(s => new Location(s.Location, s.Id, inv)).ToList();


            return(appStore.First());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Send aggregate Order to database when an order is placed
        /// </summary>
        /// <param name="order"></param>
        /// <param name="orderID"></param>
        public void SendAggOrder(IOrder order, int orderID)
        {
            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Create the aggOrders list that need to get sent
            List <AggOrder> aggOrders = new List <AggOrder>();

            // For each value in order.customer.shoppingCart, create a single aggOrder
            //   then add that aggOrder to the database
            foreach (var product in order.Customer.ShoppingCart)
            {
                AggOrder orderDetails = new AggOrder
                {
                    OrderId = orderID,
                    Product = product.Key,
                    Amount  = product.Value
                };
                context.AggOrders.Add(orderDetails);
            }
            context.SaveChanges();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a console customer complete with their order history
        /// </summary>
        /// <param name="custID"></param>
        /// <returns></returns>
        public CustomerClass GetCustomerWithOrders(int custID)
        {
            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Get all of the GenOrders from the Database, based on the storeID
            var generalOrders = context.GenOrders.Where(o => o.CustomerId == custID).ToList();
            // Create a list of orders to add to based on the orders to a store
            var aggregatedOrders = new List <IOrder>();

            // for each order to a store, get the details of it.
            foreach (var order in generalOrders)
            {
                // Get the Console Customer from the DB
                var tempCust = GetCustomerFromID(order.CustomerId);
                // Get the Console Location from the DB
                var tempLocation = GetStoreFromID(order.StoreId);
                // Add Location and Customer to the order
                Order tempOrder = new Order(tempLocation, tempCust, order.Id, order.Date);
                // Create list of all the aggregateOrders from a store Location
                var listAggOrders = context.AggOrders.Where(o => o.OrderId == order.Id);
                foreach (var agOrder in listAggOrders)
                {
                    // Add the aggregateOrders essentially as orders being placed so I can
                    //   Just keep them in memory and move them
                    tempOrder.Customer.ShoppingCart.Add(agOrder.Product, agOrder.Amount);
                }
                // Add each order with details to
                aggregatedOrders.Add(tempOrder);
            }
            // Call GetCustomer From Id passing in the customer id that was searched for
            CustomerClass customerHere = GetCustomerFromID(custID);

            // Add the list of customers orders to the console customer
            customerHere.CustomersOrders = aggregatedOrders;

            return(customerHere);
        }
        /// <summary>
        /// When the manager picks a location to view, call this method to get an entire store.
        ///     with GenOrders and Inventory.
        /// </summary>
        /// <param name="storeID"></param>
        /// <returns></returns>
        public Location GetStoreWithOrdersAndInventory(int storeID)
        {
            // Create Context
            using var context = new danielGProj0DBContext(_contextOptions);
            // Get all of the GenOrders from the Database, based on the storeID
            var generalOrders = context.GenOrders.Where(o => o.StoreId == storeID).ToList();
            // Create a list of orders to add to based on the orders to a store
            var aggregatedOrders = new List <IOrder>();

            // for each order to a store, get the details of it.
            foreach (var order in generalOrders)
            {
                // Get the Console Customer from the DB
                var tempCust = GetCustomerFromID(order.CustomerId);
                // Get the Console Location from the DB
                var tempLocation = GetStoreFromID(order.StoreId);
                // Add Location and Customer to the order
                Order tempOrder = new Order(tempLocation, tempCust, order.Id, order.Date);
                // Create list of all the aggregateOrders from a store Location
                var listAggOrders = context.AggOrders.Where(o => o.OrderId == order.Id);
                foreach (var agOrder in listAggOrders)
                {
                    // Add the aggregateOrders essentially as orders being placed so I can
                    //   Just keep them in memory and move them
                    tempOrder.Customer.ShoppingCart.Add(agOrder.Product, agOrder.Amount);
                }
                // Add each order with details to
                aggregatedOrders.Add(tempOrder);
            }
            // Call CreateStoreWithInventory so I can just return an entire store rather than just the orders to that store.
            Location chosenLocation = CreateStoreWithInventory(storeID);

            // Add the list of previous orders to that store
            chosenLocation.Orders = aggregatedOrders;
            return(chosenLocation);
        }