Пример #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);
        }
Пример #2
0
        public void ParseMatch(string round, HtmlNode table, MatchParam param)
        {
            var trs = table.SelectNodes("tbody/tr");

            foreach (var tr in trs)
            {
                var dtNode = tr.SelectSingleNode("td[@class='datetime']");
                if (dtNode == null)
                {
                    continue;
                }
                var matchDate  = dtNode.InnerText;
                var matchIdStr = tr.SelectSingleNode("td/a").Attributes["href"].Value;
                var homeNode   = tr.SelectSingleNode("td/a/img[@class='home']");
                var awayNode   = tr.SelectSingleNode("td/a/img[@class='away']");
                var homeIdStr  = homeNode == null ? "" : homeNode.Attributes["src"].Value;
                var awayIdStr  = awayNode == null ? "" : awayNode.Attributes["src"].Value;
                var p1         = tr.SelectSingleNode("td[@class='p1 ']");
                var htResult   = p1 == null ? "" : p1.InnerText;
                var ftResult   = tr.SelectSingleNode("td[@class='nt ftx ']").InnerText;

                var matchId      = RegexGetStr(matchIdStr, "matchid', ", ",");
                var currentMatch = new MatchEntity();
                currentMatch.MatchId      = matchId;
                currentMatch.HomeId       = RegexGetStr(homeIdStr, "small/", ".png");
                currentMatch.AwayId       = RegexGetStr(awayIdStr, "small/", ".png");
                currentMatch.MatchDate    = matchDate;
                currentMatch.ExtendedData = "Round = " + round;
                currentMatch.SportId      = param.SportId;
                currentMatch.SeasonId     = param.SeasonId;

                var me = MatchEntityManager.AddOrGetCacheEntity <MatchEntity>(matchId);
                me.CompareSetMatchInfo(currentMatch);

                if (!string.IsNullOrEmpty(htResult) || !string.IsNullOrEmpty(ftResult))
                {
                    var result = new MatchResultEntity()
                    {
                        MatchId = matchId,
                        Result  = htResult + "_" + ftResult,
                        SportId = param.SportId
                    };
                    me.CompareSetMatchResult(result);
                }
            }
        }
        public async Task <MatchResultEntity> SaveResultAsync(MatchResultEntity entity)
        {
            MatchResultEntity existingEntity = null;

            existingEntity = this.matchResultsRepository.Get(x => x.MatchId.Equals(entity.MatchId)).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.matchResultsRepository.SaveAsync(existingEntity);

            return(existingEntity);
        }