コード例 #1
0
        //get history (req)
        /// <summary>
        /// Given a model location, return all orders placed from that location.
        /// Also updates the model with any missing orders.
        /// </summary>
        /// <param name="l">The model location.</param>
        /// <returns>List of orders.</returns>
        public IEnumerable <IOrder> GetOrderHistory(Store.Location l)
        {
            if (l is null)
            {
                _logger.LogError("Null argument to GetOrderHistory - store");
                throw new ArgumentNullException();
            }

            Location location = _context.Locations
                                .Where(loc => loc.LocationName == l.LocationName)
                                .Include(loc => loc.Orders)
                                .ThenInclude(order => order.Customer)
                                .Include(Loc => Loc.Orders)
                                .ThenInclude(ord => ord.OrderItems)
                                .ThenInclude(ordi => ordi.Item)
                                .FirstOrDefault();

            var orders = location.Orders.ToList();

            foreach (Order LocationOrder_DB in orders)
            {
                bool foundEquiv = HasEquivilentOrder(LocationOrder_DB);

                if (!foundEquiv)
                {
                    Console.WriteLine("no equiv found, creating order.");

                    checkForModelMissingOrderData(LocationOrder_DB);
                    Db_StoreMapper.MapAndAddOrderToModel(LocationOrder_DB);
                }
            }
            return(Store.Orders.Instance.GetOrdersByLocation(l));
        }
コード例 #2
0
        //get history (req)
        /// <summary>
        /// Gets all unique order histories involving a customer, and loads them into the model
        /// if they're not already there.
        /// </summary>
        /// <param name="c">The model's version of the customer.</param>
        /// <returns> A list of all IOrders related to the customer.</returns>
        public IEnumerable <IOrder> GetOrderHistory(Store.Customer c)
        {
            Customer customer = GetDBCustomerByName(c.CustomerName);

            customer = _context.Customers
                       .Where(cust => cust.Id == customer.Id)
                       .Include(cust => cust.Orders)
                       .ThenInclude(ord => ord.OrderItems)
                       .ThenInclude(ordi => ordi.Item)
                       .Include(cust => cust.StoreLocationNavigation)
                       .FirstOrDefault();

            foreach (Order CustomerOrder_DB in customer.Orders)
            {
                bool foundEquiv = HasEquivilentOrder(CustomerOrder_DB);

                if (!foundEquiv)
                {
                    checkForModelMissingOrderData(CustomerOrder_DB);
                    Db_StoreMapper.MapAndAddOrderToModel(CustomerOrder_DB);
                }
            }

            return(Store.Orders.Instance.GetOrdersByCustomer(c));
        }
コード例 #3
0
        /// <summary>
        /// Get a list of all the Orders.
        /// </summary>
        /// <returns>A list of all the orders</returns>
        public IEnumerable <IOrder> GetAllOrders()
        {
            IEnumerable <DataModel.Order> orders = _context.Orders
                                                   .Include(order => order.Customer)
                                                   .Include(order => order.OrderItems)
                                                   .ThenInclude(oi => oi.Item)
                                                   //manafest the query here so that more queries can be made ass needed.
                                                   .ToList();


            foreach (Order Order_DB in orders)
            {
                bool foundEquiv = HasEquivilentOrder(Order_DB);

                if (!foundEquiv)
                {
                    this.checkForModelMissingOrderData(Order_DB);

                    Db_StoreMapper.MapAndAddOrderToModel(Order_DB);
                }
            }

            return(Store.Orders.Instance.GetAllOrders());
        }