예제 #1
0
        static User WelcomeOrRegister()
        {
            User user = null;

            try
            {
                user = User.GetUser();
                return(user);
            }
            catch (Exception)
            {
                var userData = new Dictionary <string, string>();
                Console.WriteLine("Greetings, first we need to know how can we call you, so fill out these fields");
NotOkay:
                Console.WriteLine("First Name: ");
                userData.Add("FirstName", Console.ReadLine());
                Console.Clear();

                Console.WriteLine("Last Name: ");
                userData.Add("LastName", Console.ReadLine());
                Console.Clear();

                Console.WriteLine("Color Scheme(example is green,black): ");
                var colorScheme = Console.ReadLine();
                userData.Add("Font", colorScheme.Substring(0, colorScheme.IndexOf(',')));
                userData.Add("BackGround", colorScheme.Substring(colorScheme.IndexOf(',') + 1));

                Console.Clear();
TryGetValidCountry:
                Console.WriteLine("Your Country and city(example is usa,new-york): ");

                var countryAndCity = Console.ReadLine();
                var country        = new Country(countryAndCity.Substring(0, countryAndCity.IndexOf(',')));
                if (Country.CheckForExistingCountry(Continents, country.Name) == false)
                {
                    Console.WriteLine("Uh,sorry there is no such country in our database");
                    goto TryGetValidCountry;
                }
                var city = countryAndCity.Substring(countryAndCity.IndexOf(',') + 1);
                if (Country.CheckForExistingCity(Continents, city) == false)
                {
                    Console.WriteLine("Uh,sorry there is no such city in our database,try again");
                    goto TryGetValidCountry;
                }
                country.Cities = new List <string> {
                    city
                };
                Console.Clear();

                Console.WriteLine("Are you ok with that?(yes/no)");
                foreach (var data in userData)
                {
                    Console.WriteLine($"{data.Key}: {data.Value}");
                }
                Console.WriteLine("Country: " + country.Name);
                Console.WriteLine("City: " + city);

                var answer = Console.ReadLine();
                if (answer == "yes" || answer == "y")
                {
                    user = new User(userData["FirstName"], userData["LastName"], new List <string> {
                        userData["Font"], userData["BackGround"]
                    }, country, city);
                    user.RegisterOrChange();
                }
                else
                {
                    goto NotOkay;
                }
                return(user);
            }
        }