Esempio n. 1
0
        public void RemoveItem(int id)
        {
            BakeryItem item = new BakeryItem("", 0, 0);

            for (int i = Items.Count - 1; i >= 0; i--)
            {
                if (Items[i].Id == id)
                {
                    item = Items[i];
                    Items.RemoveAt(i);
                    break;
                }
            }
            if (item.Id == 0)
            {
                Console.WriteLine("Item was not found!");
            }
            else
            {
                Console.WriteLine($"Item was deleted from the CART: / Id: {item.Id} , Name: {item.Name}, Cost: {item.Cost} /");

                if (CountDict.ContainsKey(item))
                {
                    CountDict[item] -= 1;
                    if (CountDict[item] <= 0)
                    {
                        CountDict.Remove(item);
                    }
                }
            }
        }
Esempio n. 2
0
 public void DisplayOrder()
 {
     Table.PrintAlign("------------------");
     Table.PrintAlign($"Cost: ${String.Format("{0:0.00}", CalculatePrice())}");
     Table.PrintAlign("------------------");
     Table.PrintAlign("Your order:");
     foreach (KeyValuePair <BakeryItem, int> kvp in CountDict)
     {
         BakeryItem item = kvp.Key;
         Table.PrintAlign($"Name: {item.Name}, Count: {kvp.Value}");
     }
 }
Esempio n. 3
0
        public void DisplayCart()
        {
            double price = CalculatePrice();

            Table.PrintAlign("------------------");
            Table.PrintAlign("CART");
            Table.PrintAlign("------------------");
            Table.PrintLine();

            if (Items.Count == 0)
            {
                Table.PrintAlign("Empty Cart");
                Table.PrintAlign("------------------");
            }
            else
            {
                Table.PrintRowWithIdCount(new string [] { "Id", "Product", "Cost", "Count" });
                Table.PrintLine();

                foreach (KeyValuePair <BakeryItem, int> kvp in CountDict)
                {
                    BakeryItem item     = kvp.Key;
                    string []  result   = item.Display();
                    string []  count    = new string[] { kvp.Value.ToString() };
                    string []  combined = new string[result.Length + count.Length];
                    Array.Copy(result, combined, result.Length);
                    Array.Copy(count, 0, combined, result.Length, count.Length);
                    Table.PrintRowWithIdCount(combined);
                    Table.PrintLine();
                }
            }

            if (Offer1 || Offer2)
            {
                Table.PrintAlign("Applied offers:");
                if (Offer1)
                {
                    Table.PrintAlign("Bread. Buy any 2, get 1 free.");
                }
                if (Offer2)
                {
                    Table.PrintAlign("Pastry. Buy any 3 for $8.");
                }
                Table.PrintAlign("------------------");
            }

            Table.PrintAlign($"Total Cost: ${String.Format("{0:0.00}", price)}");
            Table.PrintLine();
        }
Esempio n. 4
0
        public void PrintMenu()
        {
            Table.PrintAlign("------------------");
            Table.PrintAlign("MENU");
            Table.PrintAlign("------------------");
            Console.WriteLine();

            Table.PrintAlign("------------------");
            Table.PrintAlign("BREADS");
            Table.PrintAlign("------------------");
            Table.PrintLine();

            Table.PrintRowWithId(new string [] { "Id", "Name", "Price" });
            Table.PrintLine();

            for (int i = 0; i < 6; i++)
            {
                BakeryItem bread = Items[i];
                Table.PrintRowWithId(bread.Display());
                Table.PrintLine();
            }

            Table.PrintAlign("------------------");
            Table.PrintAlign("PASTRIES");
            Table.PrintAlign("------------------");
            Table.PrintLine();

            Table.PrintRowWithId(new string [] { "Id", "Name", "Price" });
            Table.PrintLine();

            for (int i = 6; i < 12; i++)
            {
                BakeryItem pastry = Items[i];
                Table.PrintRowWithId(pastry.Display());
                Table.PrintLine();
            }

            Table.PrintAlign("------------------");
            Table.PrintAlign("OFFERS");
            Table.PrintAlign("------------------");
            Table.PrintLine();

            Table.PrintRow(new string [] { "Product", "Offer" });
            Table.PrintLine();
            Table.PrintRow(new string [] { "Bread", "Buy any 2, get 1 free" });
            Table.PrintLine();
            Table.PrintRow(new string [] { "Pastry", "Buy any 3 for $8" });
            Table.PrintLine();
        }
Esempio n. 5
0
        public void AddItem(int id)
        {
            BakeryItem item = menu.FindItem(id);

            if (item.Id == 0)
            {
                Console.WriteLine("Item was not found!");
            }
            else
            {
                Items.Add(item);
                Console.WriteLine($"Item was added to the CART: / Id: {item.Id} , Name: {item.Name}, Cost: {item.Cost} /");
                if (CountDict.ContainsKey(item))
                {
                    CountDict[item] += 1;
                }
                else
                {
                    CountDict.Add(item, 1);
                }
            }
        }