public IActionResult Details(string Id) { try { var article = _article.Entity.GetById(Id); if (article != null) { var categories = _category.Entity.GetAll(); var category = categories.Where(c => c.Id == article.CategoryId).FirstOrDefault(); var publishers = _user.Entity.GetAll(); var publisher = publishers.Where(p => p.Id == article.AppUserId).FirstOrDefault(); var articleViewModel = new ArticleCommentsViewModel { Publisher = publisher, Article = article, Category = category }; article.NombreVisites++; _article.Entity.Update(article); _article.Save(); return(View(articleViewModel)); } return(NotFound()); } catch (Exception) { return(NotFound()); } }
public ActionResult RatingCreate(Guid id, int rating, int maxRating, int minRating) { if (!FeatureCheckHelper.IsFeatureEnabled(FeatureNames.Feedback)) { return(new EmptyResult()); } var context = PortalCrmConfigurationManager.CreateServiceContext(); var article = context.RetrieveSingle("knowledgearticle", FetchAttribute.All, new Condition("knowledgearticleid", ConditionOperator.Equal, id), false, false, RequestFlag.AllowStaleData); if (article == null || !Authorized(context, article)) { return(new EmptyResult()); } var articleDataAdapter = new KnowledgeArticleDataAdapter(article); TryAddUpdateRating(articleDataAdapter, rating, maxRating, minRating); var commentsViewModel = new ArticleCommentsViewModel() { KnowledgeArticle = articleDataAdapter.Select() }; return(PartialView("Rating", commentsViewModel.KnowledgeArticle)); }
public async Task <IActionResult> Article(int?id) { if (id == null) { return(NotFound()); } var model = new ArticleCommentsViewModel { Article = await ctx.Articles.FirstOrDefaultAsync(a => a.Id == id) }; if (model.Article == null) { return(NotFound()); } await IncrementArticleViewsAsync(model.Article); model.Comments = ctx.Comments.Where(comment => comment.Article.Id == model.Article.Id && comment.ParentComment == null).OrderByDescending(comment => comment.CreatedDateTime); foreach (var comment in model.Comments) { comment.SubComments = ctx.Comments.Where(subComment => subComment.Article.Id == model.Article.Id && subComment.ParentComment.Id == comment.Id) .OrderBy(subComment => subComment.CreatedDateTime); } return(View(model)); }
public ActionResult CommentCreate(Guid id, string authorName, string authorEmail, string copy) { if (!FeatureCheckHelper.IsFeatureEnabled(FeatureNames.Feedback)) { return(new EmptyResult()); } var context = PortalCrmConfigurationManager.CreateServiceContext(); var article = context.RetrieveSingle("knowledgearticle", FetchAttribute.All, new Condition("knowledgearticleid", ConditionOperator.Equal, id), false, false, RequestFlag.AllowStaleData); if (article == null || !Authorized(context, article)) { return(new EmptyResult()); } var articleDataAdapter = new KnowledgeArticleDataAdapter(article) { ChronologicalComments = true }; var sanitizedCopy = SafeHtml.SafeHtmSanitizer.GetSafeHtml(copy ?? string.Empty); TryAddComment(articleDataAdapter, authorName, authorEmail, sanitizedCopy); var commentsViewModel = new ArticleCommentsViewModel() { Comments = new PaginatedList <IComment>(PaginatedList.Page.Last, articleDataAdapter.SelectCommentCount(), articleDataAdapter.SelectComments), KnowledgeArticle = articleDataAdapter.Select() }; RouteData.Values["action"] = "Article"; RouteData.Values["id"] = Guid.Empty; return(PartialView("Comments", commentsViewModel)); }
public IActionResult AddComment([Bind("ArticleId, Author, Text")] ArticleCommentsViewModel viewModel) { var article = ctx.Articles.First(article => article.Id == viewModel.ArticleId); if (article == null) { return(NotFound()); } var comment = new Comment { CreatedDateTime = DateTime.Now, Author = viewModel.Author, Article = article, Text = viewModel.Text, }; ctx.Comments.Add(comment); ctx.SaveChanges(); return(RedirectToAction(nameof(Article), new{ id = comment.Article.Id })); }