/// <summary>
        /// Makes the user to input data about the coach.
        /// Passes the information to CoachesBusinessiness, using the method "AddCoach"
        /// </summary>
        public void AddCoach()
        {
            var coach = new Coaches();

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

            coach.SportId = sportsBusiness.GetSportByName(sportName).Id;
            coachesBusiness.AddCoach(coach);

            Console.WriteLine($"New coach successfully added!");
        }
Exemple #2
0
        public void GetSportByName()
        {
            var options = new DbContextOptionsBuilder <OlympicGamesDBContext>()
                          .UseInMemoryDatabase(databaseName: "GetSportByNameDB")
                          .Options;

            var data = new List <Sports>()
            {
                new Sports {
                    Id = 1, Name = "Sport1"
                },
                new Sports {
                    Id = 2, Name = "Sport2"
                },
                new Sports {
                    Id = 3, Name = "Sport3"
                },
            }.AsQueryable();

            using (OlympicGamesDBContext context = new OlympicGamesDBContext(options))
            {
                SportsBusiness business = new SportsBusiness(context);
                data.ToList().ForEach(t => context.Sports.Add(t));
                context.SaveChanges();

                Sports t = business.GetSportByName("Sport1");
                Assert.AreEqual("Sport1", t.Name);
            }
        }
Exemple #3
0
        /// <summary>
        /// After the user has inputed name, the program "Calls" method "GetSportByName" from SportsBusiness.
        /// Shows the Sport who has this name.
        /// </summary>
        public void GetSportByName()
        {
            Console.Write("Enter Sport Name to fetch: ");
            string name  = Console.ReadLine();
            Sports sport = sportsBusiness.GetSportByName(name);

            if (sport != null)
            {
                PrintSport(sport);
            }
            else
            {
                Console.WriteLine($"There is no sport with name = {name} in the table!");
            }
        }
Exemple #4
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);
        }