public ActionResult PostTweet() { string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var currentUser = this.Data.Users.GetAll() .Where(u => u.Id == currentUserId) .Select(UserViewModel.Create(currentUserId)) .FirstOrDefault(); var tweet = new PostTweetBindingModel { Author = new UserViewModel { Username = currentUser.Username, ProfileImage = currentUser.ProfileImage }, Content = string.Empty }; return this.PartialView("~/Views/Shared/_FormTweet.cshtml", tweet); }
public ActionResult PostTweet(PostTweetBindingModel model) { string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var user = this.Data.Users.Find(currentUserId); if (this.ModelState.IsValid) { var newTweet = new Tweet { Content = model.Content, PageUrl = string.Empty, Date = DateTime.Now, AuthorId = user.Id }; this.Data.Tweets.Add(newTweet); this.Data.SaveChanges(); TwitterHub hub = new TwitterHub(); hub.Tweet(user.Followers.Select(u => u.Id).ToList(), newTweet.Id); return this.RedirectToAction("Index", "Home", new { Message = ManageMessageId.PostTweetSucess }); } return this.RedirectToAction("Index", "Home", new { Message = ManageMessageId.Error }); }
public async Task<ActionResult> PostTweet(PostTweetBindingModel model) { string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var user = this.Data.Users.Find(currentUserId); if (this.ModelState.IsValid) { var newTweet = new Tweet { Content = model.Content, PageUrl = string.Empty, Date = DateTime.Now, AuthorId = user.Id }; this.Data.Tweets.Add(newTweet); this.Data.SaveChanges(); return this.RedirectToAction("Index", "Home"); } return this.PartialView("~/Views/Shared/_FormTweet.cshtml"); }
public ActionResult PostTweet(ManageMessageId? message) { this.ViewBag.StatusMessage = message == ManageMessageId.PostTweetSucess ? "Successfully tweet" : message == ManageMessageId.Error ? "Incorrect data. Please try again." : ""; string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); var currentUser = this.Data.Users.GetAll() .Where(u => u.Id == currentUserId) .Select(UserViewModel.Create(currentUserId)) .FirstOrDefault(); var tweet = new PostTweetBindingModel { Author = new UserViewModel { Username = currentUser.Username, ProfileImage = currentUser.ProfileImage }, Content = string.Empty }; return this.PartialView("~/Views/Shared/_FormTweet.cshtml", tweet); }