Beispiel #1
0
        private static bool NewRecord()
        {
            Person    person;
            Country   countryPerson, countryGrandPrix;
            City      city;
            GrandPrix grandprix;
            Result    result;

            person = Person.Read();
            //
            if (personRep.IsPersonExist(person))
            {
                Console.WriteLine("Skater with this name is already exist.\nTry again.");
                return(false);
            }
            countryPerson = Country.Read();
            //
            if (countryRep.IsCountryExist(countryPerson))
            {
                countryPerson = countryRep.GetSameExist(countryPerson);
            }
            countryPerson.AddPerson(person);
            grandprix = GrandPrix.Read();
            //
            if (grandprixRep.IsGrandPrixExist(grandprix))
            {
                grandprix = grandprixRep.GetSameExist(grandprix);
                Console.WriteLine(grandprix);
                result = Result.Read();
                grandprix.AddResult(result);
                person.AddResult(result);

                countryRep.Save(countryPerson);
                personRep.Save(person);
                grandprixRep.Save(grandprix);
                resultRep.Save(result);
                Console.WriteLine("Add new record:");
                Console.WriteLine(person);
                return(true);
            }
            city = City.Read();
            //
            if (cityRep.IsCityExist(city))
            {
                Console.WriteLine("Grand Prix in this city is already exist.\nTry again.");
                return(false);
            }
            city.AddGrandPrix(grandprix);
            countryGrandPrix = Country.Read();
            //
            if (countryRep.IsCountryExist(countryGrandPrix))
            {
                countryGrandPrix = countryRep.GetSameExist(countryGrandPrix);
                countryGrandPrix.AddCity(city);

                result = Result.Read();
                grandprix.AddResult(result);
                person.AddResult(result);

                countryRep.Save(countryPerson);
                countryRep.Save(countryGrandPrix);
                cityRep.Save(city);
                personRep.Save(person);
                grandprixRep.Save(grandprix);
                resultRep.Save(result);
                Console.WriteLine("Add new record:");
                Console.WriteLine(person);
                return(true);
            }
            countryGrandPrix.AddCity(city);
            result = Result.Read();
            grandprix.AddResult(result);
            person.AddResult(result);

            countryRep.Save(countryPerson);
            countryRep.Save(countryGrandPrix);
            cityRep.Save(city);
            personRep.Save(person);
            grandprixRep.Save(grandprix);
            resultRep.Save(result);
            Console.WriteLine("Add new record:");
            Console.WriteLine(person);
            return(true);
        }
Beispiel #2
0
        private static bool AddSkaterToGrandPrix()
        {
            ShowAllSkaters();
            int SkaterID;

            Console.Write("Input the skater ID: ");
            try
            {
                SkaterID = Convert.ToInt32(Console.ReadLine());
            }
            catch (FormatException)
            {
                Console.WriteLine("Be more careful and try again.");
                throw;
            }
            catch (OverflowException)
            {
                Console.WriteLine("Be more careful and try again.");
                throw;
            }

            if (!personRep.IsIDExist(SkaterID))
            {
                Console.WriteLine("Be more careful and try again.");
                return(false);
            }

            Console.Clear();
            Console.WriteLine("Skater {0} add to Grand Prix:", SkaterID);
            Person    person    = personRep.GetById(SkaterID);
            GrandPrix grandprix = GrandPrix.Read();
            Country   country;
            City      city;
            Result    result;

            //
            if (grandprixRep.IsGrandPrixExist(grandprix))
            {
                grandprix = grandprixRep.GetSameExist(grandprix);
                Console.WriteLine(grandprix);

                result = Result.Read();
                grandprix.AddResult(result);
                person.AddResult(result);

                personRep.Save(person);
                grandprixRep.Save(grandprix);
                resultRep.Save(result);
                Console.WriteLine("Add skater to Grand Prix:");
                Console.WriteLine(person);
                return(true);
            }
            //
            city = City.Read();
            //
            if (cityRep.IsCityExist(city))
            {
                Console.WriteLine("Grand Prix in this city is already exist.\nTry again.");
                return(false);
            }
            city.AddGrandPrix(grandprix);
            //
            country = Country.Read();
            if (countryRep.IsCountryExist(country))
            {
                country = countryRep.GetSameExist(country);
                country.AddCity(city);

                result = Result.Read();
                grandprix.AddResult(result);
                person.AddResult(result);

                countryRep.Save(country);
                cityRep.Save(city);
                personRep.Save(person);
                grandprixRep.Save(grandprix);
                resultRep.Save(result);
                Console.WriteLine("Add skater to Grand Prix:");
                Console.WriteLine(person);
                return(true);
            }
            country.AddCity(city);
            result = Result.Read();
            grandprix.AddResult(result);
            person.AddResult(result);

            countryRep.Save(country);
            cityRep.Save(city);
            personRep.Save(person);
            grandprixRep.Save(grandprix);
            resultRep.Save(result);
            Console.WriteLine("Add skater to Grand Prix:");
            Console.WriteLine(person);
            return(true);
        }