public IHttpActionResult GetSportsFullInformation() { OddsCollectorDbContext db = new OddsCollectorDbContext(); var sports = db.Sports .Select(s => new { Name = s.Name, Events = s.Events.Select(e => new { Name = e.Name, IsLive = e.IsLive, Matches = e.Matches.Select(m => new { Name = m.Name, StartDate = m.StartDate.ToString(), MatchType = m.MatchType, Bets = m.Bets.Select(b => new { Name = b.Name, IsLive = b.IsLive, Odds = b.Odds.Select(o => new { Name = o.Name, Value = o.Value, SpecialBetValue = o.SpecialBetValue }) }) }) }) }) .ToList(); return this.Ok(sports); }
public IHttpActionResult GetSportsWithEvents() { OddsCollectorDbContext db = new OddsCollectorDbContext(); var startDate = DateTime.Now.AddHours(-3); var endDate = DateTime.Now.AddDays(1); var sportsWithTheirEvents = db.Sports .Where(s => s.Name != null) .Where(s => s.Events.Count > 0) .Select(s => new { Id = s.Id, Name = s.Name, Events = s.Events .Where(e => e.Name != null) .Where(e => e.Matches .Where(m => m.StartDate >= startDate && m.StartDate <= endDate) .Count() > 0) .Where(e => e.Matches.Count > 0) .Select(e => new { Id = e.Id, Name = e.Name, IsLive = e.IsLive }) }) .ToList(); sportsWithTheirEvents = sportsWithTheirEvents.Where(s => s.Events.Count() > 0).ToList(); return this.Ok(sportsWithTheirEvents); }
public IHttpActionResult GetSports() { OddsCollectorDbContext db = new OddsCollectorDbContext(); var sports = db.Sports .Where(s => s.Name != null) .Select(s => s.Name) .ToList(); return this.Ok(sports); }
public IHttpActionResult GetEventFullInfo(string eventId) { OddsCollectorDbContext db = new OddsCollectorDbContext(); if(!db.Events.Where(e => e.Id == eventId).Any()) { return this.BadRequest("Event does not exist!"); } var startDate = DateTime.Now.AddHours(-3); var endDate = DateTime.Now.AddDays(1); var eventInfo = db.Events .Where(e => e.Id == eventId) .Single() .Matches .Where(m => m.StartDate >= startDate && m.StartDate <= endDate) .Select(m => new { Id = m.Id, Name = m.Name, StartDate = m.StartDate.ToString(), MatchType = m.MatchType, Bets = m.Bets.Select(b => new { Name = b.Name, IsLive = b.IsLive, Odds = b.Odds.Select(o => new { Name = o.Name, Value = o.Value, SpecialBetValue = o.SpecialBetValue }) }) }) .ToList(); return this.Ok(eventInfo); }
public string Feed() { string URLString = "http://vitalbet.net/sportxml"; OddsCollectorDbContext db = new OddsCollectorDbContext(); HttpWebRequest request = WebRequest.Create(URLString) as HttpWebRequest; HttpWebResponse response = request.GetResponse() as HttpWebResponse; if (response.StatusCode != HttpStatusCode.OK) { return "Xml feed not available atm"; } else { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); XmlTextReader xmlReader = new XmlTextReader(response.GetResponseStream()); int lastSportId = 0; string lastEventId = null; long lastMatchId = 0; long lastBetId = 0; List<Sport> sports = new List<Sport>(); List<Event> events = new List<Event>(); List<Match> matches = new List<Match>(); List<Bet> bets = new List<Bet>(); List<Odd> odds = new List<Odd>(); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.IsStartElement()) { switch (xmlReader.Name) { case "Sport": lastSportId = ExtractSport(xmlReader, sports); break; case "Event": lastEventId = ExtractEvent(xmlReader, lastSportId, events); break; case "Match": lastMatchId = ExtractMatch(xmlReader, lastEventId, matches); break; case "Bet": lastBetId = ExtractBet(xmlReader, lastMatchId, bets); break; case "Odd": ExtractOdd(xmlReader, lastBetId, odds); break; } } } db.BulkMerge(sports); db.BulkMerge(events); db.BulkMerge(matches); db.BulkMerge(bets); db.BulkMerge(odds); stopwatch.Stop(); return stopwatch.Elapsed.ToString(); } }