public async Task<ActionResult> AddComment(CreateCommentsViewModel model) { if (ModelState.IsValid) { string userId = User.Identity.GetUserId(); var activity = await db.Activities.FindAsync(model.ActivityId); var newComment = new Comment() { Description = model.Description, CommentOwner = await db.Users.FirstAsync(u => u.Id == userId), CreationDate = DateTime.Now }; activity.Comments.Add(newComment); db.SaveChanges(); } return RedirectToAction("Details", new { id = model.ActivityId }); }
// GET: Comment/AddComment/ActivityId public ActionResult AddComment(int id) { if (id <= 0) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); var model = new CreateCommentsViewModel { ActivityId = id }; return View(model); }