public static void Add(string userId, string screenName, string token, string tokenSecret) { using (CoffeeTweetDbContext db = new CoffeeTweetDbContext()) { var user = db.Users.SingleOrDefault(c => c.TwitterUserId == userId); if (user == null) { user = new CoffeeTweet.Domain.Entities.User() { TwitterUserId = userId, ScreenName = screenName, TwitterAccessKey = token, TwitterAccessSecret = tokenSecret }; db.Users.Add(user); db.SaveChanges(); } } }
public static void Add(Twitterizer.TwitterSearchResult tweet) { using (CoffeeTweetDbContext db = new CoffeeTweetDbContext()) { var user = db.Users.SingleOrDefault(c => c.TwitterUserId == tweet.FromUserId.ToString()); if (user != null) { Coffee coffee = new Coffee { TweetId = tweet.Id.ToString(), User = tweet.FromUserId.ToString(), Text = tweet.Text, CreatedDate = tweet.CreatedDate }; db.Coffees.Add(coffee); } db.SaveChanges(); } }