コード例 #1
0
        public double AddItemToKart(string name, double num, Dictionary <string, MarkdownItem> markdownItem)
        {
            Dictionary <string, StoreItem> productList = GroceryProduct.Produce();

            if (productList.Count > 0)
            {
                // trying to get value double
                if (productList.TryGetValue(name, out StoreItem storeItem))
                {
                    //if item does not exist then we add to kart // else take that item and add it to our quantity already there
                    if (!kartItems.ContainsKey(name))
                    {
                        //Item does not exists, so added it to list
                        kartItems.Add(name, new KartItem(num, PriceSelector.GetItemPrice(name, markdownItem)));
                    }
                    else
                    {
                        //If item exists increment quantity and subtotal per item
                        kartItems[name].quantity += num;
                        kartItems[name].subtotal += num * kartItems[name].unitPrice;
                    }

                    return(kartItems[name].subtotal);
                }
            }

            return(0);
        }
コード例 #2
0
ファイル: KartView.cs プロジェクト: seanjasm/Andre
        public static void DisplayItemKey(IEnumerable <KeyValuePair <string, StoreItem> > items, Dictionary <string, MarkdownItem> markdownList)
        {
            int    count = 1;
            double price = 0;

            foreach (var item in items)
            {
                price = PriceSelector.GetItemPrice(item.Key, markdownList);
                price = price > 0 ? price : item.Value.unitPrice;

                Console.WriteLine($"{count} ........ {item.Key} @ " +
                                  $"{price:C2}/{item.Value.soldBy.ToString()}");
                count++;
                price = -1;
            }
            Console.WriteLine("");
        }