public GuessMatchRespond GuessMatch(string userId, int matchId, bool isHome, bool isCancel)
 {
     var request = new GuessMatchRequest
     {
         UserId = userId,
         MatchId = matchId,
         IsGuessTeamHome = isHome,
         IsCancelGuess = isCancel
     };
     var result = FacadeRepository.Instance.MatchFacade.GuessMatch(request, DateTime.Now);
     return result;
 }
        public void WhenผใชUserIdทายผลแมชMatchIdIsGuessTeamHomeเวลาในขณะนนเปน(string userId, int matchId, bool isGuessTeamHome, DateTime currentTime)
        {
            var mockMatchDataAccess = ScenarioContext.Current.Get<Moq.Mock<IMatchDataAccess>>();
            mockMatchDataAccess.Setup(it => it.SaveGuess(It.IsAny<GuessMatchInformation>()));

            var request = new GuessMatchRequest
            {
                UserId = userId,
                MatchId = matchId,
                IsGuessTeamHome = isGuessTeamHome,
            };
            FacadeRepository.Instance.MatchFacade.GuessMatch(request, currentTime);
        }
示例#3
0
        public GuessMatchRespond GuessMatch(GuessMatchRequest request, DateTime currentTime)
        {
            var invalidRespondData = new GuessMatchRespond
            {
                IsSuccessed = false,
                AccountInfo = new AccountInformation(),
                Matches = Enumerable.Empty<MatchInformation>(),
            };

            var isArgumentsValid = request != null && !string.IsNullOrEmpty(request.UserId);
            if (!isArgumentsValid) return invalidRespondData;

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

            var limitedPastDate = currentTime.Date.AddDays(-2);
            var limitedFutureDate = currentTime.Date.AddDays(2);
            var selectedMatche = FacadeRepository.Instance.MatchDataAccess.GetAllMatches()
                .Where(it => it.BeginDate.Date >= limitedPastDate)
                .Where(it => it.BeginDate.Date <= limitedFutureDate)
                .FirstOrDefault(it => it.Id == request.MatchId);
            if (selectedMatche == null) return invalidRespondData;

            var isMatchEnableToGuess = !selectedMatche.CompletedDate.HasValue;
            if (isMatchEnableToGuess)
            {
                var updateData = new GuessMatchInformation
                {
                    AccountSecrectCode = request.UserId,
                    MatchId = request.MatchId,
                    GuessTeamId = request.IsCancelGuess ? null : request.IsGuessTeamHome ? new Nullable<int>(selectedMatche.TeamHome.Id) : new Nullable<int>(selectedMatche.TeamAway.Id),
                    PredictionPoints = request.IsCancelGuess ? 0 : request.IsGuessTeamHome ? selectedMatche.TeamHome.CurrentPredictionPoints : selectedMatche.TeamAway.CurrentPredictionPoints
                };
                FacadeRepository.Instance.MatchDataAccess.SaveGuess(updateData);
            }

            var respond = GetMatches(new GetMatchesRequest { UserId = request.UserId }, currentTime);
            return new GuessMatchRespond
            {
                IsSuccessed = true,
                AccountInfo = respond.AccountInfo,
                Matches = respond.Matches
            };
        }