public FootballGame Find(GameId gameId)
        {
            using (var context = new TimeLineContext())
            {
                var entity = context.FootballGames.SingleOrDefault(g =>
                                                                   g.AwayTeam == gameId.AwayTeam &&
                                                                   g.HomeTeam == gameId.HomeTeam &&
                                                                   g.League == gameId.League
                                                                   );

                if (entity == null)
                {
                    return(FootballGame.Null);
                }

                List <EventData> eventDatas = context.EventDatas
                                              .Where(x => x.FootballGameId == entity.Id)
                                              .ToList();

                var events = eventDatas
                             .Select(ConvertToModel);

                var game = new FootballGameProxy(entity);
                game.LoadEvents(events);
                return(game);
            }
        }
Beispiel #2
0
 protected void UnitOfWork(Action <TimeLineContext> action)
 {
     using (var context = new TimeLineContext())
     {
         action(context);
         context.SaveChanges();
     }
 }
 public bool IsTweetOfGameCollected(GameId gameId)
 {
     using (var context = new TimeLineContext())
     {
         return(context.Tweets.Count(t => t.HomeTeam == gameId.HomeTeam &&
                                     t.AwayTeam == gameId.AwayTeam &&
                                     t.League == gameId.League) > 0);
     }
 }
 public List <Tweet> GetGameTweets(GameId gameId)
 {
     using (var context = new TimeLineContext())
     {
         return(context.Tweets
                .Where(t => t.HomeTeam == gameId.HomeTeam &&
                       t.AwayTeam == gameId.AwayTeam &&
                       t.League == gameId.League)
                .ToList()
                .Select(t => new ProxyTweet(t))
                .Cast <Tweet>()
                .ToList());
     }
 }