Beispiel #1
0
        public BetResultEntity GetBetResult(MatchBetEntity bet, MatchResultEntity result)
        {
            var hitPenalties = false;

            if (result.HomePenalties.HasValue && result.AwayPenalties.HasValue)
            {
                hitPenalties = result.HomePenalties.Equals(bet.HomePenalties) && result.AwayPenalties.Equals(bet.AwayPenalties);
            }

            var betResult = new BetResultEntity
            {
                Id             = bet.Id,
                UserId         = bet.UserId,
                MatchId        = bet.MatchId,
                ResultId       = result.Id,
                HitResult      = bet.Result.Equals(result.Result),
                HitHomeGoals   = bet.HomeGoals.Equals(result.HomeGoals),
                HitAwayGoals   = bet.AwayGoals.Equals(result.AwayGoals),
                HitGoalsDif    = bet.HomeGoals - bet.AwayGoals == result.HomeGoals - result.AwayGoals,
                HitExactResult = bet.HomeGoals.Equals(result.HomeGoals) && bet.AwayGoals.Equals(result.AwayGoals),
                HitPenalties   = hitPenalties
            };

            var betPoints = 0;

            betPoints += betResult.HitResult ? BetResultPointsHelper.BetResultPoints["HitResult"] : 0;

            if (betResult.HitPenalties)
            {
                betPoints           += BetResultPointsHelper.BetResultPoints["HitPenalties"];
                betResult.ExtraPoint = true;
            }

            if (betResult.HitExactResult)
            {
                betPoints += BetResultPointsHelper.BetResultPoints["HitExactResult"];
            }
            else
            {
                betPoints           += betResult.HitHomeGoals ? BetResultPointsHelper.BetResultPoints["HitHomeGoals"] : 0;
                betPoints           += betResult.HitAwayGoals ? BetResultPointsHelper.BetResultPoints["HitAwayGoals"] : 0;
                betPoints           += betResult.HitGoalsDif && !bet.HomeGoals.Equals(bet.AwayGoals) ? BetResultPointsHelper.BetResultPoints["HitGoalsDif"] : 0;
                betResult.ExtraPoint = betResult.ExtraPoint || betResult.HitHomeGoals || betResult.HitAwayGoals || (betResult.HitGoalsDif && !bet.HomeGoals.Equals(bet.AwayGoals));
            }

            betResult.Points = betPoints;

            return(betResult);
        }
Beispiel #2
0
        public async Task <MatchBetEntity> SaveBetAsync(MatchBetEntity entity)
        {
            MatchBetEntity existingEntity = null;

            existingEntity = this.matchBetsRepository.Get(x => x.MatchId.Equals(entity.MatchId) && x.UserId.Equals(entity.UserId)).FirstOrDefault();

            if (existingEntity != null)
            {
                existingEntity.AwayGoals     = entity.AwayGoals;
                existingEntity.HomeGoals     = entity.HomeGoals;
                existingEntity.HomePenalties = entity.HomePenalties;
                existingEntity.AwayPenalties = entity.AwayPenalties;
                existingEntity.Result        = entity.Result;
            }
            else
            {
                existingEntity    = entity;
                existingEntity.Id = Guid.NewGuid();
            }

            await this.matchBetsRepository.SaveAsync(existingEntity);

            return(existingEntity);
        }
 private UserBetResultViewModel ToBetResultViewModel(MatchViewModel match, BetResultEntity betResult, MatchBetEntity bet)
 {
     return(new UserBetResultViewModel
     {
         AwayTeam = match.AwayTeam,
         AwayTeamCode = match.AwayTeamCode,
         AwayTeamGoals = match.AwayTeamGoals.Value,
         AwayTeamPenalties = match.AwayTeamPenalties,
         HomeTeam = match.HomeTeam,
         HomeTeamCode = match.HomeTeamCode,
         HomeTeamGoals = match.HomeTeamGoals.Value,
         HomeTeamPenalties = match.HomeTeamPenalties,
         PenaltiesDefinition = match.PenaltiesDefinition,
         PlayedOn = match.PlayedOn,
         Stage = match.Stage,
         BetAwayTeamGoals = bet.AwayGoals,
         BetAwayTeamPenalties = bet.AwayPenalties,
         BetHomeTeamGoals = bet.HomeGoals,
         BetHomeTeamPenalties = bet.HomePenalties,
         Points = betResult.Points,
         HitResult = betResult.HitResult,
         HitExactResult = betResult.HitExactResult,
         ExtraPoint = betResult.ExtraPoint,
         BetPenalties = match.Stage.SupportPenalties() && bet.AwayGoals == bet.HomeGoals
     });
 }