Beispiel #1
0
        public void UpdateChainRank(item item) // Chain Rank helps us decide which chain is the best
        {
            List <price> pricesForItem = new List <price>();

            foreach (var pair in _minPricesForAllChains)
            {
                price price = pair.Value.Find(x => x.item_code == item.item_code);
                if (price != null)
                {
                    pricesForItem.Add(price);
                }
            }

            price maxPrice = pricesForItem.Maximum();

            foreach (var chain in _dbManager.GetChains())
            {
                price curPrice = pricesForItem.Find(x => x.store.chain_id == chain.chain_id);

                if (curPrice != null)
                {
                    _chainRank[chain.chain_id] += (maxPrice.price1 - pricesForItem.Find(x => x.store.chain_id == chain.chain_id).price1);
                }
            }
        }
Beispiel #2
0
        private List <price> PricesToDB(FileInfo xmlFile, PriceCompareDBEntitie context)
        {
            XDocument    doc          = XDocument.Load(xmlFile.FullName);
            List <price> listOfPrices = new List <price>();
            long         chain_id;
            long         item_code;
            int          store_id;
            float        priceOfItem;

            foreach (XElement itemElement in doc.Root.Element("Items").Elements("Item"))
            {
                long.TryParse(itemElement.Element("ItemCode").Value, out item_code);
                long.TryParse(doc.Root.Element("ChainId").Value, out chain_id);
                var existingItem = context.items.FirstOrDefault(i => i.item_code == item_code);
                if (existingItem != null)
                {
                    price price = new price();
                    price.item_code = existingItem.item_code;
                    int.TryParse(doc.Root.Element("StoreId").Value, out store_id);
                    var existingStore = context.stores.FirstOrDefault(s => s.store_id == store_id && s.chain_id == chain_id);
                    price.store_key = existingStore.store_key;
                    float.TryParse(itemElement.Element("ItemPrice").Value, out priceOfItem);
                    price.price1 = priceOfItem;
                    var existingPrice = context.prices.FirstOrDefault(p => p.item_code == price.item_code && p.store_key == price.store_key);
                    if (existingPrice == null)
                    {
                        listOfPrices.Add(price);
                    }
                }
            }

            return(listOfPrices);
        }
Beispiel #3
0
        static public price Minimum(this List <price> listOfPrices)
        {
            price minPrice = listOfPrices[0];

            foreach (var price in listOfPrices)
            {
                if (price != null)
                {
                    if (price.price1 < minPrice.price1)
                    {
                        minPrice = price;
                    }
                }
            }

            return(minPrice);
        }
Beispiel #4
0
        static public price Maximum(this List <price> listOfPrices)
        {
            float max      = 0;
            price maxPrice = null;

            foreach (var price in listOfPrices)
            {
                if (price != null)
                {
                    if (price.price1 > max)
                    {
                        max      = price.price1;
                        maxPrice = price;
                    }
                }
            }

            return(maxPrice);
        }