public ActionResult _NewTweet(TweetinputModel model) { var newTweetId = this.Data.Tweets.Count() + 1; var newTweet = new Tweet() { Id = newTweetId, AuthorId = this.User.Identity.GetUserId(), DateCreated = DateTime.Now, Text = model.Text }; this.Data.Tweets.Add(newTweet); this.Data.SaveChanges(); return RedirectToAction("Index", "Home"); }
public ActionResult CreateTweet(Tweet inputTweet) { var userId = TempData["userId"]; if (String.IsNullOrEmpty(inputTweet.Text)) { return RedirectToAction("Index"); }; ApplicationUser user = this.db.Users.All().Where(us => us.Id == userId).FirstOrDefault(); Tweet tweet = new Tweet() { Author = User.Identity.Name, Text = inputTweet.Text, PostedOn = DateTime.Now }; tweet.ApplicationUser = user; this.db.Tweets.Add(tweet); this.db.SaveChanges(); return View("Index", user); }