示例#1
0
        public MatchResultsPage(string match, int tournamentId, int totalMatches)
        {
            InitializeComponent();
            var model = new MatchResultModel(match, tournamentId, Navigation, totalMatches);

            BindingContext = model;
        }
        public async Task <JsonResult> SetBetResult(MatchResultModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    if (ModelState.Any())
                    {
                        throw new Exception(ModelState.FirstOrDefault().Value.Errors[0].ErrorMessage);
                    }
                    else
                    {
                        throw new Exception("El modelo no es valido!");
                    }
                }

                var match = this.matchesService.GetMatch(model.Id);
                if (match.PlayedOn.Value <= DateTime.UtcNow)
                {
                    throw new Exception("El partido ya ha iniciado!");
                }

                await this.matchBetsService.SaveBetAsync(new MatchBetEntity
                {
                    MatchId       = model.Id,
                    UserId        = IdentityHelper.GetUserId(User.Identity),
                    HomeGoals     = model.HomeGoals,
                    AwayGoals     = model.AwayGoals,
                    HomePenalties = model.HomePenalties,
                    AwayPenalties = model.AwayPenalties,
                    Result        = model.GetResult(match)
                });

                return(Json("Ok"));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(new
                {
                    ExceptionMessage = ex.Message
                }));
            }
        }
示例#3
0
        public MatchResultModel Find(IEnumerable <HtmlNode> nodes, HtmlNode originNode)
        {
            var result     = new MatchResultModel();
            int maxMatches = 0;

            foreach (var node in nodes)
            {
                int matchCount = 0;
                Dictionary <string, string> matchParams = new Dictionary <string, string>();
                foreach (var originalAttribute in originNode.Attributes)
                {
                    if (node.Attributes.Contains(originalAttribute.Name) && string.Equals(node.Attributes[originalAttribute.Name].Value, originalAttribute.Value))
                    {
                        matchParams.Add(originalAttribute.Name, originalAttribute.Value);
                        matchCount++;
                    }
                }

                if (string.Equals(node.Name, originNode.Name))
                {
                    matchParams.Add("TagName", node.Name);
                    matchCount++;
                }


                if (string.Equals(node.InnerText.Trim(), originNode.InnerText.Trim()))
                {
                    matchParams.Add("Text", originNode.InnerText.Trim());
                    matchCount++;
                }


                if (matchCount > maxMatches && matchCount > 2)
                {
                    maxMatches         = matchCount;
                    result.Element     = node;
                    result.MatchParams = matchParams;
                }
            }

            return(result);
        }