private static string SetSeason()
 {
     using (var context = new FcDeHoekContext())
     {
         var season = SeasonQueries.GetCurrentSeason(context);
         return($"{season.SeasonStartYear} - {season.SeasonEndYear}");
     }
 }
        private Dictionary <DateTime, List <GameModel> > GetGamesPerDate(FcDeHoekContext context, List <Game> calendars)
        {
            var dictionary    = new Dictionary <DateTime, List <GameModel> >();
            var currentSeason = SeasonQueries.GetCurrentSeason(context);
            var gamesDeHoek   = GameQueries.GetAllGamesByIdSeasonAndIdTeam(context, currentSeason.IdSeason, 1).OrderBy(g => g.MatchDate).ToList();

            foreach (var deHoekGame in gamesDeHoek)
            {
                var gamesForMatchDate = calendars.Where(c => c.MatchDate == deHoekGame.MatchDate).ToList();
                dictionary.Add(deHoekGame.MatchDate, GetGameModels(context, gamesForMatchDate, false));
            }

            return(dictionary);
        }
 public ActionResult AllGames()
 {
     using (var context = new FcDeHoekContext())
     {
         var currentSeason = SeasonQueries.GetCurrentSeason(context);
         var calendars     = GameQueries.GetAllGamesByIdSeason(context, currentSeason.IdSeason).OrderBy(g => g.MatchDate).ToList();
         var model         = new FullCalendarModel
         {
             SeasonDescription =
                 $"{currentSeason.SeasonStartYear} - {currentSeason.SeasonEndYear}",
             GamesPerDate = GetGamesPerDate(context, calendars)
         };
         return(View(model));
     }
 }
        private List <SeasonModel> GetAllSeasons()
        {
            using (var context = new FcDeHoekContext())
            {
                var seasons       = context.Seasons.ToList();
                var currentSeason = SeasonQueries.GetCurrentSeason(context);
                var seasonModels  = new List <SeasonModel>();
                foreach (var season in seasons)
                {
                    seasonModels.Add(MapSeasonToSeasonModel(season, currentSeason));
                }

                return(seasonModels);
            }
        }
Exemple #5
0
        private List <FcDeHoekGame> GetAllFcDeHoekGames(FcDeHoekContext context, DateTime matchDate)
        {
            var gameModelList = new List <FcDeHoekGame>();
            var season        = SeasonQueries.GetSeasonByDate(context, matchDate) ?? SeasonQueries.GetCurrentSeason(context);
            var games         = GameQueries.GetAllGamesByIdSeasonAndIdTeam(context, season.IdSeason, 1).ToList();

            foreach (var game in games)
            {
                gameModelList.Add(new FcDeHoekGame
                {
                    IdGame      = game.IdGame,
                    MatchDate   = game.MatchDate,
                    GameFixture = $"{game.GameHomeTeam.Name} - {game.GameAwayTeam.Name}"
                });
            }

            return(gameModelList);
        }
Exemple #6
0
        private StatisticsModel GetPlayerStats(FcDeHoekContext context, int idPerson)
        {
            var stats = new StatisticsModel
            {
                FriendlyGamesPlayed = 0,
                GoalsInFriendly     = 0,
                AssistsInFriendly   = 0,

                LeagueGamesPlayed = 0,
                GoalsInLeague     = 0,
                AssistsInLeague   = 0,

                CupGamesPlayed = 0,
                GoalsInCup     = 0,
                AssistsInCup   = 0,
            };

            var allPlayerStats  = PersonStatisticsQueries.GetByIdPerson(context, idPerson).ToList();
            var season          = SeasonQueries.GetCurrentSeason(context);
            var leagueGameIds   = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context, season.IdSeason, eCompetitionType.League).Select(lg => lg.IdGame).ToList();
            var friendlyGameIds = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context, season.IdSeason, eCompetitionType.Friendly).Select(lf => lf.IdGame).ToList();
            var cupGameIds      = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context, season.IdSeason, eCompetitionType.Cup).Select(lc => lc.IdGame).ToList();

            foreach (var playerStat in allPlayerStats)
            {
                if (leagueGameIds.Contains(playerStat.IdGame))
                {
                    if (playerStat.Played ?? false)
                    {
                        stats.LeagueGamesPlayed++;
                    }

                    stats.GoalsInLeague   += playerStat.Goals ?? 0;
                    stats.AssistsInLeague += playerStat.Assists;
                }

                if (friendlyGameIds.Contains(playerStat.IdGame))
                {
                    if (playerStat.Played ?? false)
                    {
                        stats.FriendlyGamesPlayed++;
                    }

                    stats.GoalsInFriendly   += playerStat.Goals ?? 0;
                    stats.AssistsInFriendly += playerStat.Assists;
                }

                if (cupGameIds.Contains(playerStat.IdGame))
                {
                    if (playerStat.Played ?? false)
                    {
                        stats.CupGamesPlayed++;
                    }

                    stats.GoalsInCup   += playerStat.Goals ?? 0;
                    stats.AssistsInCup += playerStat.Assists;
                }
            }

            stats.TotalGamesPlayed = stats.FriendlyGamesPlayed + stats.LeagueGamesPlayed + stats.CupGamesPlayed;
            stats.TotalGoalsScored = stats.GoalsInFriendly + stats.GoalsInLeague + stats.GoalsInCup;
            stats.TotalAssists     = stats.AssistsInFriendly + stats.AssistsInLeague + stats.AssistsInCup;

            return(stats);
        }
        private List <RankModel> BuildLeagueRanking()
        {
            using (var context = new FcDeHoekContext())
            {
                var model    = new List <RankModel>();
                var allGames = GameQueries.GetAllGamesByIdSeasonAndIdCompetition(context,
                                                                                 SeasonQueries.GetCurrentSeason(context).IdSeason, eCompetitionType.League).ToList();



                var allPlayedGames = allGames.Where(g => g.GoalsHomeTeam != null && g.GoalsAwayTeam != null).ToList();

                var teams = new List <string>();
                teams.AddRange(allGames.Select(g => g.GameHomeTeam.Name).Distinct().ToList());
                teams.AddRange(allGames.Select(g => g.GameAwayTeam.Name).Distinct().ToList());
                teams = teams.Distinct().ToList();

                if (teams.Count < allPlayedGames.Count && allPlayedGames.Count == 0)
                {
                    return(CreateZeroRanking(teams));
                }

                foreach (var team in teams)
                {
                    var ranking = new RankModel {
                        Team = team
                    };

                    var homeGames = allPlayedGames.Where(g => g.GameHomeTeam.Name == team).ToList();
                    foreach (var homeGame in homeGames)
                    {
                        ranking.GoalsScored   += homeGame.GoalsHomeTeam ?? 0;
                        ranking.GoalsConceded += homeGame.GoalsAwayTeam ?? 0;

                        if (homeGame.GoalsHomeTeam > homeGame.GoalsAwayTeam)
                        {
                            ranking.GamesWon += 1;
                        }
                        else if (homeGame.GoalsHomeTeam == homeGame.GoalsAwayTeam)
                        {
                            ranking.GamesDrawn += 1;
                        }
                        else
                        {
                            ranking.GamesLost += 1;
                        }

                        ranking.GamesPlayed++;
                    }

                    var awayGames = allPlayedGames.Where(g => g.GameAwayTeam.Name == team).ToList();
                    foreach (var awayGame in awayGames)
                    {
                        ranking.GoalsScored   += awayGame.GoalsAwayTeam ?? 0;
                        ranking.GoalsConceded += awayGame.GoalsHomeTeam ?? 0;

                        if (awayGame.GoalsAwayTeam > awayGame.GoalsHomeTeam)
                        {
                            ranking.GamesWon += 1;
                        }
                        else if (awayGame.GoalsHomeTeam == awayGame.GoalsAwayTeam)
                        {
                            ranking.GamesDrawn += 1;
                        }
                        else
                        {
                            ranking.GamesLost += 1;
                        }

                        ranking.GamesPlayed++;
                    }

                    model.Add(ranking);
                }

                foreach (var ranking in model)
                {
                    ranking.Points = (ranking.GamesWon * 3) + ranking.GamesDrawn;
                }

                return(model.OrderByDescending(m => m.Points).ThenByDescending(m => m.GamesWon).ThenByDescending(m => (m.GoalsScored - m.GoalsConceded)).ThenByDescending(m => m.GoalsScored).ToList());
            }
        }
Exemple #8
0
        public ActionResult Save(GameManagerModel model)
        {
            using (var context = new FcDeHoekContext())
            {
                var game = GameQueries.GetById(context, model.Games[0].IdGame);
                if (game == null)
                {
                    game = new Game();
                }

                foreach (var gameModel in model.Games)
                {
                    game.GoalsAwayTeam   = gameModel.GoalsAwayTeam;
                    game.GoalsHomeTeam   = gameModel.GoalsHomeTeam;
                    game.Forfait         = gameModel.Forfait;
                    game.IdCompetition   = gameModel.IdCompetition;
                    game.IdAwayTeam      = gameModel.IdAwayTeam;
                    game.IdHomeTeam      = gameModel.IdHomeTeam;
                    game.IdPostPonedGame = gameModel.IdPostPonedGame;
                    game.IdSeason        = SeasonQueries.GetSeasonByDate(context, gameModel.MatchDay)?.IdSeason ?? SeasonQueries.GetCurrentSeason(context).IdSeason;
                    game.MatchDate       = gameModel.MatchDay;
                    game.NotPlayed       = gameModel.IsPostPoned;

                    context.Games.AddOrUpdate(game);
                    context.SaveChanges();
                }


                if (model.AddAnother)
                {
                    if (model.Games.Count > 1)
                    {
                        return(RedirectToAction("AddMultipleGames", "GameManager", new { idGame = 0 }));
                    }
                    else
                    {
                        return(RedirectToAction("EditGame", "GameManager", new { idGame = 0 }));
                    }
                }


                return(RedirectToAction("Index", "GameManager"));
            }
        }
Exemple #9
0
        private ScoreModel GetScores(DateTime?fixtureDate)
        {
            using (var context = new FcDeHoekContext())
            {
                if (fixtureDate == null)
                {
                    fixtureDate = DateTime.Now.GetFirstDayOfWeek(CultureInfo.CurrentCulture);
                }

                var allGames     = GameQueries.GetAllGamesByIdSeason(context, SeasonQueries.GetSeasonByDate(context, (DateTime)fixtureDate)?.IdSeason ?? SeasonQueries.GetCurrentSeason(context).IdSeason).OrderBy(g => g.MatchDate).ToList();
                var allPlayWeeks = new List <DateTime>();
                foreach (var game in allGames)
                {
                    if (!allPlayWeeks.Contains(game.MatchDate))
                    {
                        allPlayWeeks.Add(game.MatchDate);
                    }
                }

                var model = new ScoreModel
                {
                    AllFixtureDates = allPlayWeeks,
                    Games           = GetGameModels(context, (DateTime)fixtureDate)
                };

                model.FixtureDate = model.Games.FirstOrDefault()?.MatchDay ?? DateTime.Now;

                return(model);
            }
        }
        private string GetCurrentDivision(FcDeHoekContext context)
        {
            var currentSeason = SeasonQueries.GetCurrentSeason(context);

            return($"{currentSeason.Division}de Reeks");
        }