public PricingLogicManager()
 {
     User          = string.Empty;
     AccQuery      = new AccountQuery();
     ItemQuery     = new ItemQuery();
     StoreQuery    = new StoreQuery();
     HistItemQuery = new HistItemQuery();
     userCart      = new Cart();
 }
        public List <CartItem> GetItems(string input, bool includeInnerItems)
        {
            List <Item> items = ItemQuery.FilterGeneralItems(input);

            if (includeInnerItems)
            {
                items.AddRange(ItemQuery.FilterInnerItems(input));
            }

            return(items.OrderBy(i => i.ItemCode).Select(i => new CartItem()
            {
                ItemCode = i.ItemCode,
                ItemType = i.ItemType,
                ItemName = i.ItemName,
                ChainId = i.ChainID,
                Amount = 0,
                Price = 0
            }).ToList());
        }
        public List <UpdatedCart> CalculateTotal(List <long> chains, string location, int productsToFetch)
        {
            UpdatedCarts = new List <UpdatedCart>();
            List <StoreHeader> markedStores         = new List <StoreHeader>();
            List <KeyValuePair <long, int> > idData = new List <KeyValuePair <long, int> >();
            int uniqueFetchs;

            if (chains.Count >= productsToFetch)
            {
                uniqueFetchs = productsToFetch;
            }
            else
            {
                uniqueFetchs = chains.Count;
            }
            for (int i = 0; i < uniqueFetchs; i++)
            {
                idData = ItemQuery.GetCheapestStore(new List <long>()
                {
                    chains[i]
                }, userCart.Items, location, markedStores, 1);
                if (idData.Count > 0)
                {
                    StoreHeader storeData = StoreQuery.GetStoreHeader(idData.First().Key, idData.First().Value);
                    UpdateCart(storeData);
                    markedStores.Add(storeData);
                }
            }
            if (UpdatedCarts.Count > 0 &&
                UpdatedCarts.Count < productsToFetch)
            {
                idData = ItemQuery.GetCheapestStore(chains, userCart.Items, location, markedStores, productsToFetch - UpdatedCarts.Count);
                foreach (var id in idData)
                {
                    StoreHeader storeData = StoreQuery.GetStoreHeader(id.Key, id.Value);
                    UpdateCart(storeData);
                }
            }
            return(UpdatedCarts.OrderBy(c => c.TotalPrice).ToList());
        }
        public void UpdateCart(StoreHeader storeData)
        {
            UpdatedCart currCart = new UpdatedCart(storeData.StoreId, storeData.ChainId, storeData.StoreName, storeData.ChainName);

            currCart.Items = userCart.Items.Select(i => new CartItem()
            {
                ItemCode = i.ItemCode,
                ItemType = i.ItemType,
                ItemName = i.ItemName,
                ChainId  = i.ChainId,
                Amount   = i.Amount,
                Price    = 0
            }).ToList();
            foreach (CartItem item in currCart.Items)
            {
                if (item.ItemType != 0 ||
                    item.ChainId == currCart.ChainID)
                {
                    item.Price = ItemQuery.GetPrice(currCart.ChainID, currCart.StoreID, item.ItemCode, item.ItemType);
                }
            }
            UpdatedCarts.Add(currCart);
        }
 public ItemInfo GetItemInfo(CartItem currItem)
 {
     return(ItemQuery.GetItemInfo(currItem));
 }