Beispiel #1
0
        public static void ShowKartItems(KartItem kartItems)
        {
            foreach (var item in kartItems.kartItems)
            {
                Console.WriteLine($"{item.Key}   {item.Value.quantity}@{item.Value.unitPrice:C2}/{item.Value.soldBy.ToString()}" +
                                  $"    {item.Value.subtotal:C2}");
            }

            Console.ReadKey();
        }
Beispiel #2
0
 public static void DisplayKart(KartItem kartItems)
 {
     if (kartItems.kartItems.Count > 0)
     {
         KartView.ShowKartItems(kartItems);
     }
     else
     {
         UserInput.Message("Nothing to display..");
     }
 }
Beispiel #3
0
        public static void AddItemToKart(KartItem kartItem, Dictionary <string, MarkdownItem> markdownItem)
        {
            string name = UserInput.GetInput("Enter name:");

            //Ensures that the name is valid. Case sensitive
            while (!StoreItemController.IsItemNameValid(name))
            {
                UserInput.Message("Item name is not valid. Names are case sensitive.", false);
                name = UserInput.GetInput("Enter name:");
            }
            double amount = 0;

            while (!double.TryParse(UserInput.GetInput("Amount:"), out amount))
            {
                UserInput.Message("not a valid amount:", false);
            }

            kartItem.AddItemToKart(name, amount, markdownItem);
        }
Beispiel #4
0
        public static void RemoveItem(KartItem kart)
        {
            if (kart.kartItems.Count == 1)
            {
                //Use LinQ to retrieve the key of the first item
                string key = (from item in kart.kartItems
                              select item.Key).FirstOrDefault();

                RemoveItemByName(kart, key);
                Console.ReadLine();
            }
            else if (kart.kartItems.Count > 0)
            {
                DisplayKart(kart);
                RemoveItemByName(kart, UserInput.GetInput("Enter name of item to remove:"));
                Console.ReadLine();
            }
            else
            {
                UserInput.Message("Nothing to delete!");
                return;
            }
        }
Beispiel #5
0
        public static void RemoveItemByName(KartItem kart, string name)
        {
            if (!kart.kartItems.ContainsKey(name))
            {
                UserInput.Message("Item not found...");
                return;
            }

            //If quantity is one, then remove item from the dictionary list
            if (kart.kartItems[name].quantity <= 1)
            {
                kart.kartItems.Remove(name);
            }
            else
            {
                //Gets the amount to remove if greater than 1
                if (double.TryParse(UserInput.GetInput("Enter amount to remove:"), out double amount))
                {
                    //If the amount to be deleted is greater than or equal the amount in the cart
                    //Then remove the item from the cart
                    if (kart.kartItems[name].quantity <= amount)
                    {
                        kart.kartItems.Remove(name);
                    }
                    else
                    {
                        //Otherwise decrement the item quantity
                        kart.kartItems[name].quantity -= amount;
                    }
                    Console.WriteLine("Done..");
                }
                else
                {
                    UserInput.Message("Not a valid number unit");
                }
            }
        }