public async Task <ActionResult> Insert(ArticleCommentMultiViewModel model) { try { var newComment = new Comment() { CommentContent = model.NewComment.CommentContent, UserId = model.CommenterId, ArticleId = model.Article.ArticleId }; await new Repository.CommentRepo().InsertAsync(newComment); return(RedirectToAction("Single", "Article", new { id = model.Article.ArticleId, route = model.Article.Header.Replace(' ', '-') })); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(RedirectToAction("Single", "Article", new { id = model.Article.ArticleId, route = model.Article.Header.Replace(' ', '-') })); } }
public async Task <ActionResult> Single(int id, string route) { try { var article = await new Repository.ArticleRepo().GetByIdAsync(id); if (article == null) { return(RedirectToAction("Index", "Home")); } var comments = new Repository.CommentRepo().Queryable().Where(x => x.ArticleId == id).OrderByDescending(x => x.CommentDate).ToList(); var model = new ArticleCommentMultiViewModel() { Article = article, Comments = comments }; return(View(model)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(RedirectToAction("Index", "Home")); } }