Example #1
0
        public void AddGamestoDatabase()
        {
            using (var context = new NHLContext())
            {
                //TODO - refactor converting string searched team to teams.ID into a fucntion to be reused elsewhere
                Console.WriteLine("Enter game date : ");
                DateTime gameDate = DateTime.Parse(Console.ReadLine());
                Console.WriteLine("Enter Home Team : ");
                string homeTeam   = Console.ReadLine();
                var    homeTeamID = from t in context.Teams
                                    where t.TeamName == homeTeam
                                    select t.ID;

                Console.WriteLine("Enter Away Team : ");
                string awayTeam   = Console.ReadLine();
                var    awayTeamID = from t in context.Teams
                                    where t.TeamName == awayTeam
                                    select t.ID;

                Console.WriteLine("Enter Home Score : ");
                int homeScore = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter Away Score : ");
                int awayScore = int.Parse(Console.ReadLine());

                var game = new Games(gameDate, homeTeamID.First(), awayTeamID.First(), homeScore, awayScore);


                context.Games.Add(game);

                context.SaveChanges();
            }
        }
 public void UpdateTeamsTable()
 {
     using (var context = new NHLContext())
     {
         var resultID = context.TempScoreTable.SingleOrDefault(t => t.SearchedTeamID == SearchedTeamID);
         if (resultID != null)
         {
             resultID.GoalAllowed = GoalAllowed;
             resultID.GoalScored  = GoalScored;
             context.SaveChanges();
         }
     }
 }
Example #3
0
        public List <Games> DisplayLast3MatchForSearchedTeam(int searchedTeam)
        {
            using (var context = new NHLContext())
            {
                int searchedTeamID = searchedTeam;
                //int goalScored = 0;
                //int goalAllowed = 0;
                var query = context.Games.Where(g => g.AwayTeamID.Equals(searchedTeamID) || g.HomeTeamID.Equals(searchedTeamID))
                            .OrderByDescending(g => g.GameDate)
                            .Take(3);

                return(query.ToList());
            }
        }
Example #4
0
        public void DisplayGames()
        {
            using (var context = new NHLContext())
            {
                var query =
                    from g in context.Games
                    join t1 in context.Teams on g.AwayTeamID equals t1.ID
                    join t2 in context.Teams on g.HomeTeamID equals t2.ID
                    select new { AwayTeam = t1.TeamName, HomeTeam = t2.TeamName, AwayScore = g.AwayScore, HomeScore = g.HomeScore };



                foreach (var game in query)
                {
                    Console.WriteLine("Away Team : " + game.AwayTeam + " " + game.AwayScore + "\n" + "Home Team : " + game.HomeTeam + " " + game.HomeScore);
                    Console.WriteLine("******************");
                }
            }
        }
Example #5
0
        public void GetTopScoringTeams()
        {
            using (var context = new NHLContext())
            {
                var query = context.TempScoreTable
                            .Join(context.Teams,
                                  tempScore => tempScore.SearchedTeamID,
                                  teams => teams.ID,
                                  (tempScore, teams) => new { TempScoreTable = tempScore, Teams = teams })
                            .OrderByDescending(c => c.TempScoreTable.GoalScored)
                            .Take(3);

                //foreach (var team in query)
                //{
                //    Console.WriteLine(team.Teams.TeamName + " " + team.TempScoreTable.GoalScored);

                //}

                Console.WriteLine(query.GetType());
            }
        }
Example #6
0
        //public void DisplayLast3MatchForSearchedTeam(int searchedTeam)
        //{
        //    using (var context = new NHLContext())
        //    {
        //        int searchedTeamID = searchedTeam;
        //        int goalScored = 0;
        //        int goalAllowed = 0;
        //        var query = context.Games.Where(g => g.AwayTeamID.Equals(searchedTeamID) || g.HomeTeamID.Equals(searchedTeamID))
        //            .OrderByDescending(g => g.GameDate)
        //            .Take(3);



        //        foreach (var game in query)
        //        {
        //            if(game.AwayTeamID == searchedTeamID)
        //            {
        //                goalScored += game.AwayScore;
        //                goalAllowed += game.HomeScore;

        //            }
        //            else if(game.HomeTeamID == searchedTeamID)
        //            {
        //                goalScored += game.HomeScore;
        //                goalAllowed += game.AwayScore;

        //            }


        //        }
        //        Console.WriteLine(goalScored + " " + goalAllowed);
        //    }
        //}



        public void DisplayTeamLast3GamesWithGoalForAndGoalAgainst()
        {
            using (var context = new NHLContext())
            {
                Console.WriteLine("Please enter the team name : ");
                string searchedTeam = Console.ReadLine().ToString();
                int    goalScored   = 0;
                int    goalAllowed  = 0;
                var    query        =
                    from g in context.Games
                    join t1 in context.Teams on g.AwayTeamID equals t1.ID
                    join t2 in context.Teams on g.HomeTeamID equals t2.ID
                    select new { AwayTeam = t1.TeamName, HomeTeam = t2.TeamName, AwayScore = g.AwayScore, HomeScore = g.HomeScore };

                foreach (var game in query)
                {
                    if (game.AwayTeam == searchedTeam || game.HomeTeam == searchedTeam)
                    {
                        if (game.AwayTeam == searchedTeam)
                        {
                            goalScored  += game.AwayScore;
                            goalAllowed += game.HomeScore;
                        }
                        else
                        {
                            goalScored  += game.HomeScore;
                            goalAllowed += game.AwayScore;
                        }

                        Console.WriteLine("Away Team : " + game.AwayTeam + " " + game.AwayScore + "\n" + "Home Team : " + game.HomeTeam + " " + game.HomeScore);
                        Console.WriteLine("******************");
                    }
                }

                Console.WriteLine($"{searchedTeam} scored {goalScored} goals during the last 3 matches");
                Console.WriteLine($"{searchedTeam} allowed {goalAllowed} goals during the last 3 matches");
            }
        }