예제 #1
0
        public void GetTownByName()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetTownByNameDB")
                          .Options;

            var data = new List <Towns>()
            {
                new Towns {
                    Id = 1, Name = "Town1"
                },
                new Towns {
                    Id = 2, Name = "Town2"
                },
                new Towns {
                    Id = 3, Name = "Town3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                TownsBusiness business = new TownsBusiness(context);
                data.ToList().ForEach(t => business.AddTown(t));

                Towns t = business.GetTownByName("Town1");
                Assert.AreEqual("Town1", t.Name);
            }
        }
예제 #2
0
        /// <summary>
        /// After the user has inputed name, the program "Calls" method "GetTownByName" from TownsBusiness.
        /// Shows the Town who has this name.
        /// </summary>
        public void GetTownByName()
        {
            Console.WriteLine("Enter Town Name to fetch: ");
            string name = Console.ReadLine();
            Towns  town = townsBusiness.GetTownByName(name);

            if (town != null)
            {
                PrintTown(town);
            }
            else
            {
                Console.WriteLine($"There is no town with Name = {name} in the table!");
            }
        }
예제 #3
0
        private Competitors CreateCompetitor(Competitors competitor)
        {
            Console.Write("Enter Competitor Full Name: ");
            competitor.FullName = Console.ReadLine();
            Console.Write("Enter Competitor Birth Date: ");
            competitor.BirthDate = Console.ReadLine();
            Console.Write("Enter Competitor Age: ");
            competitor.Age = int.Parse(Console.ReadLine());
            Console.Write("Enter Competitor Gender: ");
            competitor.Gender = Console.ReadLine();
            Console.Write("Enter Competitor Weight: ");
            competitor.Weight = Console.ReadLine();

            Console.Write("Enter Competitor Town Name: ");
            string townName = Console.ReadLine();

            if (townsBusiness.GetTownByName(townName) == null)
            {
                Console.WriteLine($"There is no town with the name {townName}");
                Console.WriteLine("Do you want to create new town?");
                Console.WriteLine("1. Yes" + "\n" + "2. No");
                if (int.Parse(Console.ReadLine()) == 1)
                {
                    townsDisplay.AddTown();
                }
                else
                {
                    Console.Write("Enter existing town: ");
                    townName = Console.ReadLine();
                }
            }
            competitor.TownId = townsBusiness.GetTownByName(townName).Id;

            Console.WriteLine("Do your competitor have a club?" + "\n" + "1.Yes" + "\n" + "2.No");
            if (int.Parse(Console.ReadLine()) == 1)
            {
                Console.Write("Enter Competitor Club Name: ");
                string clubName = Console.ReadLine();
                if (clubsBusiness.GetClubByName(clubName) == null)
                {
                    Console.WriteLine($"There is no club with the name {clubName}");
                    Console.WriteLine("Do you want to create new club?");
                    Console.WriteLine("1. Yes" + "\n" + "2. No");
                    if (int.Parse(Console.ReadLine()) == 1)
                    {
                        clubsDisplay.AddClub();
                    }
                    else
                    {
                        Console.WriteLine("Enter existing club: ");
                        clubName = Console.ReadLine();
                    }
                }
                competitor.ClubId = clubsBusiness.GetClubByName(clubName).Id;
            }
            else
            {
                competitor.ClubId = null;
            }

            Console.WriteLine("Do your competitor have a coach?" + "\n" + "1.Yes" + "\n" + "2.No");
            if (int.Parse(Console.ReadLine()) == 1)
            {
                Console.Write("Enter Competitor Coach Name: ");
                string coachName = Console.ReadLine();
                if (coachesBusiness.GetCoachByName(coachName) == null)
                {
                    Console.WriteLine($"There is no coach with the name {coachName}");
                    Console.WriteLine("Do you want to create new coach?");
                    Console.WriteLine("1. Yes" + "\n" + "2. No");
                    if (int.Parse(Console.ReadLine()) == 1)
                    {
                        coachesDisplay.AddCoach();
                    }
                    else
                    {
                        Console.WriteLine("Enter existing coach: ");
                        coachName = Console.ReadLine();
                    }
                }
                competitor.CoachId = coachesBusiness.GetCoachByName(coachName).Id;
            }
            else
            {
                competitor.CoachId = null;
            }

            Console.Write("Enter Competitor Sport Name: ");
            string sportName = Console.ReadLine();

            competitor.SportId = sportsBusiness.GetSportByName(sportName).Id;

            return(competitor);
        }