public ActionResult NewComment(string textComment) { int id = (int) TempData["CurrentArticle"]; if (!string.IsNullOrEmpty(textComment)) { var user = _userService.GetUserEntity(User.Identity.Name); var comment = new CommentModel { Id = _commentService.GetLastId(), Author = User.Identity.Name, Date = DateTime.Now.ToString(), TextComment = textComment, ArticleId = id, AvatarPath = user.AvatarPath }; _commentService.CreateComment(comment.ToCommentEntity(user.Id)); if (Request.IsAjaxRequest()) { TempData["CurrentArticle"] = id; return Json(comment); } } return RedirectToAction("Details", "Article", new {id = id}); }
public ActionResult Details(string id) { try { var art = GetArticle(id); _articleService.IncrementViews(art.Id); art.Comments = new List<CommentModel>(); art.Views++; var comments = _commentService.GetAllCommentEntities(art.Id).ToList(); foreach (var comment in comments) { var user = _userService.GetUserEntity(comment.UserId); var c = new CommentModel() { Id = comment.Id, ArticleId = comment.ArticleId, TextComment = comment.CommentText, Date = comment.DateAdded.ToString(), Author = user.UserName, AvatarPath = user.AvatarPath }; art.Comments.Add(c); } return View(art); } catch (ArgumentOutOfRangeException) { return RedirectToAction("Error", "Home"); } catch (NullReferenceException) { return RedirectToAction("Error", "Home"); } }