示例#1
0
        public async Task <IEnumerable <GamePick> > GetByUserAndWeekAsync(long userId, int week)
        {
            var user = await _userRepository.GetById(userId);

            if (user == null)
            {
                return(new List <GamePick>());
            }

            var games        = _gameRepository.GetByWeek(week).ToList();
            var currentPicks = _mapper.Map <IEnumerable <GamePick> >(
                _gamePickRepository.GetByUserAndWeek(userId, week)).ToList();

            // Ensure picks are created first
            await EnsurePicksExistAsync(games, user, week);
            await SortAndFillPickWagersAsync(games, userId, week);

            return(_mapper.Map <IEnumerable <GamePick> >(
                       _gamePickRepository.GetByUserAndWeek(userId, week)));
        }
示例#2
0
        public List <WeekSummary> GetWeekSummaries(int week)
        {
            var summaries = new List <WeekSummary>();
            var users     = _mapper.Map <IEnumerable <User> >(_userRepository.GetAll().ToList());

            foreach (var user in users)
            {
                var  summary    = new WeekSummary(user, week);
                var  picks      = _gamePickRepository.GetByUserAndWeek(user.Id, week);
                bool madePick   = false;
                bool missedPick = false;

                foreach (var pick in picks)
                {
                    if (CorrectPick(pick.Pick, pick.Game))
                    {
                        summary.Score += pick.Wager;
                        summary.CorrectPicks++;
                    }

                    missedPick = pick.Pick == GameResult.NotPlayed ? true : missedPick;
                    madePick   = pick.Pick == GameResult.NotPlayed ? madePick : true;
                }

                summary.PickStatus = (madePick) ? (missedPick ? WeekPickStatus.PartiallyPicked :
                                                   WeekPickStatus.FullyPicked)
                                : WeekPickStatus.NotPicked;

                summaries.Add(summary);
            }

            HandleMissedWeek(summaries, week);

            SetBaseSummaryPlaces(summaries);

            return(summaries);
        }