コード例 #1
0
ファイル: OddsController.cs プロジェクト: ThomasHatle/GO
        public ActionResult GetEvents(Int32 sportid, Int32 leagueid)
        {
            XmlDocument eventsDoc = GetPinnacleXmlFeed(eventsURL + "?sportid=" + sportid + "&leagueid=" + leagueid);

            XmlNodeList events = eventsDoc.SelectNodes("//event");

            List<Event> eventsList = new List<Event>();

            // EACH EVENT
            foreach (XmlNode e in events)
            {
                List<Period> periods = new List<Period>();

                // EACH PERIOD (match, 1st half, 2nd half etc)
                foreach (XmlNode p in e.SelectSingleNode("periods").SelectNodes("period"))
                {
                    List<Spread> spreads = new List<Spread>();
                    List<Total> totals = new List<Total>();
                    List<TeamTotal> teamTotals = new List<TeamTotal>();
                    Moneyline moneyline = new Moneyline();

                    // EACH SPREAD (-1.5 etc)
                    if (p.SelectSingleNode("spreads") != null)
                    {
                        foreach (XmlNode s in p.SelectSingleNode("spreads").SelectNodes("spread"))
                        {
                            Spread spread = new Spread
                            {
                                HomeSpread = double.Parse(s.SelectSingleNode("homeSpread").InnerText, System.Globalization.CultureInfo.InvariantCulture),
                                AwaySpread = double.Parse(s.SelectSingleNode("awaySpread").InnerText, System.Globalization.CultureInfo.InvariantCulture),
                                HomePrice = AmericanToDecimalOdds(double.Parse(s.SelectSingleNode("homePrice").InnerText, System.Globalization.CultureInfo.InvariantCulture)),
                                AwayPrice = AmericanToDecimalOdds(double.Parse(s.SelectSingleNode("awayPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture))
                            };

                            spreads.Add(spread);
                        }
                    }

                    // EACH TOTAL (over/under points)
                    if (p.SelectSingleNode("totals") != null)
                    {
                        foreach (XmlNode t in p.SelectSingleNode("totals").SelectNodes("total"))
                        {
                            Total total = new Total
                            {
                                Points = double.Parse(t.SelectSingleNode("points").InnerText, System.Globalization.CultureInfo.InvariantCulture),
                                OverPrice = AmericanToDecimalOdds(double.Parse(t.SelectSingleNode("overPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture)),
                                UnderPrice = AmericanToDecimalOdds(double.Parse(t.SelectSingleNode("underPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture))
                            };

                            totals.Add(total);
                        }
                    }

                    // EACH TEAM TOTAL (over/under team points)
                    if (p.SelectSingleNode("teamTotals") != null)
                    {
                        foreach (XmlNode tt in p.SelectNodes("teamTotals"))
                        {
                            TeamTotal teamTotal = new TeamTotal
                            {
                                HomeTeamTotal =  double.Parse(tt.SelectSingleNode("homeTeamTotal/total").InnerText, System.Globalization.CultureInfo.InvariantCulture),
                                HomeTeamOverPrice = AmericanToDecimalOdds(double.Parse(tt.SelectSingleNode("homeTeamTotal/overPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture)),
                                HomeTeamUnderPrice = AmericanToDecimalOdds(double.Parse(tt.SelectSingleNode("homeTeamTotal/underPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture)),
                                AwayTeamTotal =  double.Parse(tt.SelectSingleNode("awayTeamTotal/total").InnerText, System.Globalization.CultureInfo.InvariantCulture),
                                AwayTeamOverPrice = AmericanToDecimalOdds(double.Parse(tt.SelectSingleNode("awayTeamTotal/overPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture)),
                                AwayTeamUnderPrice = AmericanToDecimalOdds(double.Parse(tt.SelectSingleNode("awayTeamTotal/underPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture))
                            };

                            teamTotals.Add(teamTotal);
                        }
                    }

                    // MONEYLINE
                    if (p.SelectSingleNode("moneyLine") != null)
                    {
                        if (p.SelectSingleNode("moneyLine/homePrice") != null)
                        {
                            moneyline.HomePrice = AmericanToDecimalOdds(double.Parse(p.SelectSingleNode("moneyLine/homePrice").InnerText, System.Globalization.CultureInfo.InvariantCulture));
                        }
                        if (p.SelectSingleNode("moneyLine/drawPrice") != null)
                        {
                            moneyline.DrawPrice = AmericanToDecimalOdds(double.Parse(p.SelectSingleNode("moneyLine/drawPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture));
                        }
                        if (p.SelectSingleNode("moneyLine/awayPrice") != null)
                        {
                            moneyline.AwayPrice = AmericanToDecimalOdds(double.Parse(p.SelectSingleNode("moneyLine/awayPrice").InnerText, System.Globalization.CultureInfo.InvariantCulture));
                        }
                    }

                    Period prd = new Period
                    {
                        ApiLineID = Convert.ToInt32(p.Attributes["lineId"].Value),
                        Number = Convert.ToInt32(p.SelectSingleNode("number").InnerText),
                        Description = p.SelectSingleNode("description").InnerText,
                        Spreads = spreads,
                        Totals = totals,
                        Moneyline = moneyline,
                        TeamTotals = teamTotals
                    };

                    if (prd.Number == 0)
                    {
                        prd.DescriptionShort = "FullTime";
                    }
                    else if (prd.Number == 1)
                    {
                        prd.DescriptionShort = "FirstHalf";
                    }
                    else if (prd.Number == 2)
                    {
                        prd.DescriptionShort = "SecondHalf";
                    }

                    periods.Add(prd);
                }

                Event evt = new Event
                {
                    ApiID = Convert.ToInt32(e.SelectSingleNode("id").InnerText),
                    ApiLeagueID = Convert.ToInt32(e.ParentNode.ParentNode.SelectSingleNode("id").InnerText),
                    ApiSportID = Convert.ToInt32(e.ParentNode.ParentNode.ParentNode.ParentNode.SelectSingleNode("id").InnerText),
                    IsLive = e.SelectSingleNode("IsLive").InnerText,
                    ApiStartDateTime = DateTime.Parse(e.SelectSingleNode("startDateTime").InnerText, System.Globalization.CultureInfo.InvariantCulture),
                    //ApiStartDateTime = e.SelectSingleNode("startDateTime").InnerText,
                    HomeTeam = e.SelectSingleNode("homeTeam/name").InnerText,
                    AwayTeam = e.SelectSingleNode("awayTeam/name").InnerText,
                    Periods = periods.OrderBy(x => x.Number)
                };

                eventsList.Add(evt);
            }

            eventsList = eventsList.OrderBy(x => x.ApiStartDateTime).ToList();

            League league = new League();
            league = db.Leagues.Where(x => x.ApiID == leagueid).ToList().First();

            OddsModel om = new OddsModel
            {
                Events = eventsList,
                Sports = null,
                Leagues = null,
                League = league
            };

            return Json(new { success = true, message = "success", cssclass = "success", obj = om, partialView = RenderRazorViewToString("_EventsPartial", om) }, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
ファイル: OddsController.cs プロジェクト: ThomasHatle/GO
        protected List<League> GetLeagues(Int32 sportid)
        {
            try
            {
                XmlDocument leaguesDoc = GetPinnacleXmlFeed(leaguesURL + "?sportid=" + sportid);

                // Henter angitte sporter som er lagret i DB (Satt av admin)
                var res = db.Leagues.Where(x => x.Active && x.ApiSportID == sportid);

                List<League> activeLeagues = new List<League>();
                if (res != null && res.Count() > 0)
                {
                    foreach (League l in res)
                    {
                        XmlNode leagueNode = leaguesDoc.SelectSingleNode("//leagues/league[@feedContents='1' and @id='" + l.ApiID + "']");
                        if (leagueNode != null)
                        {
                            League league = new League
                            {
                                ApiID = l.ApiID,

                                Name = l.Name,
                                ShortName = l.ShortName,
                                Active = true,
                                Country = new Country
                                {
                                    ID = l.Country.ID,
                                    Name = Resource.ResourceManager.GetString(l.Country.ShortName)
                                }
                            };
                            activeLeagues.Add(league);
                        }
                    }
                }

                activeLeagues = activeLeagues.OrderBy(x => x.Country.Name).ToList();

                return activeLeagues;

            }
            catch (WebException ex)
            {
                return null;
            }
        }