//id is comment id public ActionResult EditComment(int id,CommentFormViewModel model) { UserEntity currentUser = userService.GetByLogin(Request.GetCurrentUserLogin()); if (currentUser.Ban) return RedirectToAction("BanPage", "Account"); if (ModelState.IsValid) { if (commentService.GetById(id).AuthorId == currentUser.Id) { commentService.Edit(id, model.Comment); return View(); } } //TODO return page where we now return RedirectToAction("Index", "Home"); }
//id is comment id public ActionResult EditComment(int id) { CommentEntity comment = commentService.GetById(id); if (comment!=null) { TempData[commentModelKey] = new CommentFormViewModel() { Comment = comment.Message, CommentId = id, ArticleId = comment.ArticleId }; TempData["user"] = userService.GetByLogin(Request.GetCurrentUserLogin()).ToPlUser(); return Redirect(@"~/Article/Show/" + comment.ArticleId.ToString()); } return RedirectToAction("Index", "Home"); }
///id is articleId public ActionResult AddComment(int id,CommentFormViewModel commentModel) { UserEntity currentUser = userService.GetByLogin(Request.GetCurrentUserLogin()); if (currentUser.Ban) return RedirectToAction("BanPage", "Account"); if (ModelState.IsValid) { if (commentModel.CommentId == 0) { //add new comment commentService.Create(new CommentEntity() { ArticleId = id, AuthorId = userService.GetByLogin(Request.GetCurrentUserLogin()).Id, Message = commentModel.Comment }); } else//edit comment { commentService.Edit(commentModel.CommentId, commentModel.Comment); } } return Redirect(@"~/Article/Show/"+id.ToString()); }