public void WhenผใชUserIdขอขอมลการทายผลทงหมด(string userId)
 {
     var currentTime = ScenarioContext.Current.Get<DateTime>();
     var request = new GetAllGuessHistoryRequest { UserId = userId };
     var result = FacadeRepository.Instance.AccountFacade.GetAllGuessHistory(request, currentTime);
     ScenarioContext.Current.Set(result);
 }
Пример #2
0
        public GetAllGuessHistoryRespond GetAllGuessHistory(GetAllGuessHistoryRequest request, DateTime currentTime)
        {
            var invalidRespondData = new GetAllGuessHistoryRespond
            {
                CurrentDate = currentTime,
                Histories = Enumerable.Empty<GuessHistoryMonthlyInformation>()
            };
            var areArgumentsValid = request != null && !string.IsNullOrEmpty(request.UserId);
            if (!areArgumentsValid) return invalidRespondData;

            var accountDac = FacadeRepository.Instance.AccountDataAccess;
            var guessedMatches = accountDac.GetGuessMatchsByAccountSecrectCode(request.UserId);
            if (guessedMatches == null) return invalidRespondData;

            var matches = FacadeRepository.Instance.MatchDataAccess.GetAllMatches()
                .Where(it => it.BeginDate.Year == currentTime.Year)
                .Where(it => guessedMatches.Any(s => s.MatchId == it.Id))
                .ToList();

            foreach (var match in matches)
            {
                var guess = guessedMatches.First(it => it.MatchId == match.Id);
                var isPlayerGuessMatch = guess != null && guess.GuessTeamId.HasValue;
                if (!isPlayerGuessMatch) continue;

                var isSelectionGuessValid = guess.GuessTeamId.Value == match.TeamHome.Id || guess.GuessTeamId.Value == match.TeamAway.Id;
                if (!isSelectionGuessValid) continue;

                var isGuessTeamHome = guess.GuessTeamId.Value == match.TeamHome.Id;
                var selectedTeam = isGuessTeamHome ? match.TeamHome : match.TeamAway;
                selectedTeam.IsSelected = true;
                selectedTeam.WinningPredictionPoints = guess.PredictionPoints;
            }

            var qry = from match in matches
                      group match by match.BeginDate.ToString("MMyy") into grouping
                      select grouping;

            var result = new List<GuessHistoryMonthlyInformation>();
            foreach (var item in qry)
            {
                var DateGroup = item.First().BeginDate;
                var totalPoints = (int)item.Where(it => it.CompletedDate.HasValue).Sum(it =>
                {
                    var selectedTeam = it.TeamAway.IsSelected ? it.TeamAway : it.TeamHome;
                    var opponentTeam = it.TeamAway.IsSelected ? it.TeamHome : it.TeamAway;

                    if (selectedTeam.CurrentScore > opponentTeam.CurrentScore) return selectedTeam.WinningPredictionPoints;
                    else if (selectedTeam.CurrentScore == opponentTeam.CurrentScore) return (int)(selectedTeam.WinningPredictionPoints / 2);
                    else return 0;
                });
                result.Add(new GuessHistoryMonthlyInformation
                {
                    Month = DateGroup.Month,
                    TotalPoints = totalPoints
                });
            }

            return new GetAllGuessHistoryRespond
            {
                CurrentDate = currentTime,
                Histories = result
            };
        }
Пример #3
0
 public GetAllGuessHistoryRespond GetAllGuessHistory(string userId)
 {
     var request = new GetAllGuessHistoryRequest { UserId = userId };
     var result = FacadeRepository.Instance.AccountFacade.GetAllGuessHistory(request, DateTime.Now);
     return result;
 }