public Tweet GetTweet(Guid targetId)
 {
     using (var context = new TweetDbContext())
     {
         return(context.Tweets.FirstOrDefault(t => t.Id == targetId));
     }
 }
 public List <Tweet> GetAllTweets()
 {
     using (var context = new TweetDbContext())
     {
         return(context.Tweets.ToList());
     }
 }
示例#3
0
 public User GetUser(Guid userId)
 {
     using (var context = new TweetDbContext())
     {
         return(context.Users.FirstOrDefault(u => u.UserId == userId));
     }
 }
示例#4
0
 public List <User> GetAllUsers()
 {
     using (var context = new TweetDbContext())
     {
         return(context.Users.ToList());
     }
 }
 public void DeleteTweet(Tweet tweet)
 {
     using (var context = new TweetDbContext())
     {
         context.Tweets.Remove(tweet);
         context.SaveChanges();
     }
 }
 public void SaveTweet(Tweet tweet)
 {
     using (var context = new TweetDbContext())
     {
         context.Tweets.Add(tweet);
         context.SaveChanges();
     }
 }
        public List <Tweet> GetUserTweets(Guid userId)
        {
            using (var context = new TweetDbContext())
            {
                // Retrieve all tweets posted by the user.
                IEnumerable <Tweet> result = context.Tweets.Where(t => t.UserId == userId);

                // Order by upload date, starting at the most recent.
                result = result.OrderByDescending(t => t.PostDate);

                return(result.ToList());
            }
        }