Exemplo n.º 1
0
        public ActionResult SaveFcDeHoekGame(FcDeHoekGameModel model)
        {
            using (var context = new FcDeHoekContext())
            {
                var statsToRemove = context.PersonStatistics.Where(ps => ps.IdGame == model.IdGame).ToList();
                if (statsToRemove.Any())
                {
                    context.PersonStatistics.RemoveRange(statsToRemove);
                    context.SaveChanges();
                }

                foreach (var player in model.PlayersInGame)
                {
                    if (player.IdPlayer != -1)
                    {
                        var stat = new PersonStats
                        {
                            IdGame   = model.IdGame,
                            IdPerson = player.IdPlayer,
                            Assists  = player.AssistsGiven,
                            Goals    = player.GoalsScored,
                            Played   = true
                        };
                        context.PersonStatistics.AddOrUpdate(stat);
                        context.SaveChanges();
                    }
                }

                return(FcDeHoekGameDetail(model.IdGame));
            }
        }
Exemplo n.º 2
0
        private object GetGameModel(FcDeHoekContext context, Game game)
        {
            var model = new FcDeHoekGameModel();

            model.MatchDate   = game.MatchDate;
            model.IdGame      = game.IdGame;
            model.GameFixture = $"{game.GameHomeTeam.Name} - {game.GameAwayTeam.Name}";
            model.GoalsHome   = game.GoalsHomeTeam ?? 0;
            model.GoalsAway   = game.GoalsAwayTeam ?? 0;

            model.AllGames = GetAllFcDeHoekGames(context, game.MatchDate);

            var players = PersonQueries.GetPlayers(context).ToList();

            model.AllPlayers    = SetAllPlayers(players);
            model.PlayersInGame = GetPlayersInGame(context, players, game.IdGame);

            return(model);
        }