Example #1
0
        private void _CreateItem(string itemType)
        {
            Console.Clear();

            Console.Write("Produktnamn: ");
            var name = Console.ReadLine();

            Console.Write("Typ: ");
            var type = Console.ReadLine();

            string marking = "";
            if (itemType == "juice")
            {
                Console.Write("Ekologisk märkning: ");
                marking = Console.ReadLine();
            }

            var stockCount = _GetNumberFromUser("Antal: ", 0);

            try
            {
                switch (itemType)
                {
                    case "juice":
                        var juice = new Juice() { Id = 0, Name = name, Type = type, Marking = marking, StockCount = stockCount };
                        ActiveStock.AddItem(juice);
                        break;
                    case "plate":
                        ActiveStock.AddItem(
                            new Plate() { Id = 0, Name = name, Type = type, StockCount = stockCount }
                            );
                        break;
                    default:
                        throw new Exception(itemType + " is not a valid product type.");
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Varan kunde inte läggas till.");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Tryck på valfri tangent för att fortsätta.");
                Console.ReadKey();
            }

            _PrintCreateMenu();
        }
Example #2
0
        private Stock _CreateDummyData()
        {
            Stock stock = new Stock();

            Juice appleJuice = new Juice() { Id = 0, Name = "Brädhult", Type = "Apple", Marking = "Krav", StockCount = 20 };
            Juice orangeJuice = new Juice() { Id = 0, Name = "Plankhult", Type = "Orange", Marking = "EG", StockCount = 25 };

            Plate redPlate = new Plate() { Id = 0, Name = "Plåthult", Type = "Deep", StockCount = 125 };
            Plate bluePlate = new Plate() { Id = 0, Name = "Porslinhult", Type = "Flat", StockCount = 321 };

            stock.AddItem((StockItem)appleJuice);
            stock.AddItem((StockItem)orangeJuice);
            stock.AddItem((StockItem)redPlate);
            stock.AddItem((StockItem)bluePlate);

            return stock;
        }