예제 #1
0
        public IActionResult OnGet()
        {
            Predictions = _predictionData.GetAll();
            var EntityGames = Predictions.Select(p => p.Game).Distinct().OrderBy(g => g.Order);

            Games = new List <GameEditModel>();
            foreach (var game in EntityGames)
            {
                if (Games.All(g => g.Id != game.Id))
                {
                    Games.Add(_gameConverter.ToEditModel(game));
                }
            }
            Users       = _userData.GetAll();
            TotalScores = new Dictionary <int, int>();
            foreach (var user in Users)
            {
                var total = 0;
                foreach (var p in Predictions.Where(p => p.User.Id == user.Id))
                {
                    total += _scoreCalculator.Calculate(p.Game.HalftimeScore, p.Game.FulltimeScore, p.HalftimeScore,
                                                        p.FulltimeScore);
                }
                TotalScores.Add(user.Id, total);
            }
            return(Page());
        }
        public async Task <IList <PredictionViewModel> > GetPredictionsForYearAsync(int year)
        {
            if (Predictions == null)
            {
                Predictions = await GetAllPredictionsAsync();
            }

            return(Predictions.Where(p => p.Year == year).ToList());
        }
예제 #3
0
        private void SaveFavourites()
        {
            PersistenceService.DeleteFavourites().Wait();
            var favourites = Predictions.Where(x => x.Favourite)
                             .Select(x => new FavouriteDTO {
                StockId = x.TrainingSession.Stock.GetUniqueId()
            }).ToList();

            if (favourites.Any())
            {
                PersistenceService.SaveFavourites(favourites).Wait();
            }
        }
예제 #4
0
        public ScoreModel GetScoreForUser(GameEditModel game, int user)
        {
            // return ordered list of predictions for a game
            var prediction = Predictions.Where(p => p.Game.Id == game.Id).FirstOrDefault(p => p.User.Id == user);
            var score      = new ScoreModel();

            if (prediction != null)
            {
                score.HalftimeScore = prediction.HalftimeScore;
                score.FulltimeScore = prediction.FulltimeScore;
                score.Points        = _scoreCalculator.Calculate(game.HalftimeScore, game.FulltimeScore, prediction.HalftimeScore, prediction.FulltimeScore);
            }
            ;
            return(score);
        }