public ActionResult Reply(int id, ReplyTweetBindingModel model) { if (!this.ModelState.IsValid) { return Json(this.ModelState); } var replyTo = this.Data.Tweets.Find(id); if (replyTo == null) { return this.Json("Not found"); } var user = this.Data.Users.Find(this.User.Identity.GetUserId()); this.Data.Tweets.Add(new Tweet() { Content = model.Content, UserId = user.Id, TweetDate = DateTime.Now, ReplyToId = replyTo.Id }); this.Data.SaveChanges(); return RedirectToAction("Index", "Home"); }
public ActionResult Reply(int id, ReplyTweetBindingModel model) { if (model == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Missing data"); } if (!this.ModelState.IsValid) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest, JsonConvert.SerializeObject(this.ModelState)); } var replyTo = this.Data.Tweets.Find(id); if (replyTo == null) { return new HttpStatusCodeResult(HttpStatusCode.NotFound, "Tweet not found"); } var user = this.Data.Users.Find(this.User.Identity.GetUserId()); this.Data.Tweets.Add(new Tweet() { Content = model.Content, UserId = user.Id, TweetDate = DateTime.Now, ReplyToId = replyTo.Id }); this.Data.SaveChanges(); return RedirectToAction("Index", "Home"); }