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);
            }
        }
Ejemplo n.º 2
0
 protected void UnitOfWork(Action <TimeLineContext> action)
 {
     using (var context = new TimeLineContext())
     {
         action(context);
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
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());
     }
 }