Пример #1
0
        public void Run()
        {
            Console.WriteLine("Custom World Viewer and Editor v1.0.0.");
            Console.WriteLine("Добро пожаловать! Нажмите любую кнопку, чтобы продолжить.");
            Console.ReadLine();

            bool flag = true;

            while (flag)
            {
                cities    = citiesService.SelectCities();
                countries = countriesService.SelectCountries();
                streets   = streetService.SelectStreets();
                switch (MainMenu())
                {
                case 1:
                {
                    PrintCountries();
                    Console.WriteLine("Введите индекс: ");

                    if (int.TryParse(Console.ReadLine(), out int countryIndex))
                    {
                        if (countryIndex > 0 && countries.Count >= countryIndex)
                        {
                            Console.WriteLine($"Города страны \"{countries[countryIndex - 1].Name}\":");
                            PrintCities(countryIndex - 1);

                            int cityIndex = 0;
                            switch (CitiesMenu())
                            {
                            case 1:
                            {
                                Console.WriteLine("Введите название: ");
                                City city = new City()
                                {
                                    Name      = Console.ReadLine(),
                                    CountryId = countries[countryIndex - 1].Id
                                };
                                citiesService.InsertCity(city);
                                break;
                            }

                            case 2:
                            {
                                Console.WriteLine("Введите индекс: ");
                                if (int.TryParse(Console.ReadLine(), out cityIndex))
                                {
                                    if (cityIndex > 0 && cities.Count >= cityIndex)
                                    {
                                        City city = cities[countryIndex - 1];
                                        Console.WriteLine("Введите новое название: ");
                                        string newName = Console.ReadLine();
                                        citiesService.UpdateCity(city, newName);
                                    }
                                }
                                break;
                            }

                            case 3:
                            {
                                Console.WriteLine("Введите индекс: ");
                                if (int.TryParse(Console.ReadLine(), out cityIndex))
                                {
                                    if (cityIndex > 0 && cities.Count >= cityIndex)
                                    {
                                        City city = cities[countryIndex - 1];
                                        citiesService.DeleteCity(city);
                                    }
                                }
                                break;
                            }

                            case 4:
                            {
                                Console.WriteLine("Введите индекс города: ");
                                if (int.TryParse(Console.ReadLine(), out cityIndex))
                                {
                                    if (cityIndex > 0 && cities.Count >= cityIndex)
                                    {
                                        PrintStreets(cityIndex - 1);
                                        int menuStreet = StreetsMenu();
                                        if (menuStreet == 1)
                                        {
                                            Console.WriteLine("Введите название улицы: ");
                                            string streetName = Console.ReadLine();
                                            Street street     = new Street()
                                            {
                                                Name   = streetName,
                                                CityId = cities[cityIndex - 1].Id
                                            };

                                            streetService.InsertStreet(street);
                                        }
                                        else if (menuStreet == 2)
                                        {
                                            Console.WriteLine("Введите индекс улицы: ");
                                            if (int.TryParse(Console.ReadLine(), out int index))
                                            {
                                                if (index > 0 && index <= streets.Count)
                                                {
                                                    streetService.DeleteStreet(streets[index - 1]);
                                                }
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                            }
                        }
                    }
                    break;
                }

                case 2:
                {
                    Console.WriteLine("Введите название страны!");
                    string cityName = Console.ReadLine();
                    countriesService.InsertCountry(new Country
                        {
                            Name = cityName
                        });
                    Console.ReadLine();
                    break;
                }

                case 3:
                    Environment.Exit(0);
                    break;
                }
            }
        }