コード例 #1
0
ファイル: Kart.cs プロジェクト: seanjasm/Andre
        public static double AddProduce(string name, double num)
        {
            Dictionary <string, StoreItem> ProduceList = new Dictionary <string, StoreItem>();

            ProduceList = GroceryProduct.Produce();

            if (ProduceList.Count > 0)
            {
                // trying to get value double
                if (ProduceList.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 (!kart.TryGetValue(name, out KartItem item))
                    {
                        kart.Add(name, new KartItem(num, storeItem.unitPrice));
                    }
                    else
                    {
                        kart[name].quantity += num;
                    }

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

            return(0);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: KartController.cs プロジェクト: seanjasm/Andre
        public static void ListItemByCategory(string category, Dictionary <string, MarkdownItem> markdownList)
        {
            //Using LinQ to get all the key for items by category
            var items = from item in GroceryProduct.Produce()
                        where item.Value.category == category
                        select item;

            KartView.DisplayItemKey(items, markdownList);
        }
コード例 #4
0
        //testing one thing and one output
        public void Produce()
        {
            //im expecting the double of 4.39 from the key of "okra"
            double expected = 4.39;
            // we put only okra because the value(okra) automaticly includes the key
            var actual = GroceryProduct.Produce()["Okra"].unitPrice;

            // .equals compares
            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public static double GetItemPrice(string name, Dictionary <string, MarkdownItem> markdownList)
        {
            //double price = 0;

            if (markdownList.ContainsKey(name))
            {
                return(markdownList[name].unitPrice);
            }
            return(GroceryProduct.Produce()[name].unitPrice);
        }
コード例 #6
0
ファイル: MarkdownController.cs プロジェクト: seanjasm/Andre
        public static bool AddItem(string name, double price, Dictionary <string, MarkdownItem> markdownList, double amount = 1)
        {
            StoreItem storeItem = GroceryProduct.Produce()[name];

            if (storeItem is null)
            {
                return(false);
            }

            if (ItemExists(name, markdownList))
            {
                markdownList[name].quantity += amount;
                markdownList[name].unitPrice = price;
            }
            else
            {
                MarkdownItem markdownItem = new MarkdownItem(price, amount);
                markdownItem.soldBy = storeItem.soldBy;

                markdownList.Add(name, markdownItem);
            }

            return(true);
        }
コード例 #7
0
ファイル: StoreItemController.cs プロジェクト: seanjasm/Andre
 public static bool IsItemNameValid(string name)
 {
     return(GroceryProduct.Produce().ContainsKey(name));
 }