Ejemplo n.º 1
0
        public static void ExecuteCommandReader(IReaderService proxy, int op)
        {
            string name = "";

            if (op != 0)
            {
                name = HelperFunctions.ReadDatabaseName();
            }
            try
            {
                switch (op)
                {
                case 1:
                    CheckIfExecuted(proxy.CreateDB(name).Item1);
                    break;

                case 2:
                    CheckIfExecuted(proxy.DeleteDB(name).Item1);
                    break;

                case 3:
                    Element tmpElem = Element.LoadFromConsole();
                    CheckIfExecuted(proxy.WriteDB(name, tmpElem).Item1);
                    break;

                case 4:
                    List <Element> elems = proxy.ReadDB(name).Item1;
                    Console.WriteLine("Ids of all elements:");
                    DisplayAllElements(elems, true);

                    Element toEdit = GetElementToEdit(elems);

                    Element newElem = Element.LoadFromConsole();
                    newElem.Id = toEdit.Id;
                    CheckIfExecuted(proxy.EditDB(name, newElem).Item1);
                    break;

                case 5:
                    DisplayAllElements(proxy.ReadDB(name).Item1);
                    break;

                case 6:
                    string city = HelperFunctions.ReadCity();
                    float  medianMonthlyIncomeByCity = proxy.MedianMonthlyIncomeByCity(name, city).Item1;
                    if (medianMonthlyIncomeByCity >= 0)
                    {
                        Console.WriteLine("Prosecna plata za grad " + city + ": " + medianMonthlyIncomeByCity);
                    }
                    break;

                case 7:
                    string country = HelperFunctions.ReadCountry();
                    Console.WriteLine("Unesi godinu:");
                    int   year = int.Parse(Console.ReadLine());
                    float medianMonthlyIncome = proxy.MedianMonthlyIncome(name, country, year).Item1;
                    if (medianMonthlyIncome >= 0)
                    {
                        Console.WriteLine("Prosecna plata za " + country + " u " + year + " god.:" + medianMonthlyIncome);
                    }
                    break;

                case 8:
                    var tmpDict = proxy.MaxIncomeByCountry(name).Item1;
                    Console.WriteLine("Najveca plata za svaku drzavu:");
                    foreach (KeyValuePair <string, Element> kvp in tmpDict)
                    {
                        Console.WriteLine(kvp.Key + " : id:" + kvp.Value.Id + " plata:" + kvp.Value.Income);
                    }
                    break;

                case 0:
                    Console.WriteLine("Cao poz");
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }