public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { ArticleTypeWidget currentWidget = widget as ArticleTypeWidget; var types = _articleTypeService.Get(m => m.ParentID == currentWidget.ArticleTypeID); int ac = actionContext.RouteData.GetCategory(); ArticleType articleType = null; if (ac > 0) { articleType = _articleTypeService.Get(ac); } if (actionContext.RouteData.GetCategoryUrl().IsNullOrEmpty() && articleType != null) { if (articleType.Url.IsNotNullAndWhiteSpace()) { actionContext.RedirectTo($"{actionContext.RouteData.GetPath()}/{articleType.Url}", true); } } if (articleType != null) { var layout = actionContext.HttpContext.GetLayout(); if (layout != null && layout.Page != null) { layout.Page.Title = articleType.SEOTitle ?? articleType.Title; layout.Page.MetaKeyWorlds = articleType.SEOKeyWord; layout.Page.MetaDescription = articleType.SEODescription; } } return(widget.ToWidgetViewModelPart(new ArticleTypeWidgetViewModel { ArticleTypes = types, ArticleTypeID = ac })); }
public override object Display(WidgetDisplayContext widgetDisplayContext) { ArticleTypeWidget currentWidget = widgetDisplayContext.Widget as ArticleTypeWidget; var types = _articleTypeService.Get(m => m.ParentID == currentWidget.ArticleTypeID); var actionContext = widgetDisplayContext.ActionContext; int ac = actionContext.RouteData.GetCategory(); ArticleType articleType = null; if (ac > 0) { articleType = _articleTypeService.Get(ac); } if (actionContext.RouteData.GetCategoryUrl().IsNullOrEmpty() && articleType != null) { if (articleType.Url.IsNotNullAndWhiteSpace()) { actionContext.RedirectTo($"{actionContext.RouteData.GetPath()}/{articleType.Url}", true); } } if (articleType != null && articleType.SEOTitle.IsNotNullAndWhiteSpace()) { var layout = widgetDisplayContext.PageLayout; if (layout != null && layout.Page != null) { layout.Page.ConfigSEO(articleType.SEOTitle, articleType.SEOKeyWord, articleType.SEODescription); } } return(new ArticleTypeWidgetViewModel { ArticleTypes = types, ArticleTypeID = ac }); }
public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { var currentWidget = widget as ArticleListWidget; var categoryEntity = _articleTypeService.Get(currentWidget.ArticleTypeID); int pageIndex = actionContext.RouteData.GetPage(); int cate = actionContext.RouteData.GetCategory(); var pagin = new Pagination { PageIndex = pageIndex, PageSize = currentWidget.PageSize ?? 20, OrderByDescending = "PublishDate" }; IEnumerable <ArticleEntity> articles; Expression <Func <ArticleEntity, bool> > filter = null; if (cate != 0) { filter = m => m.IsPublish && m.ArticleTypeID == cate; } else { var ids = _articleTypeService.Get(m => m.ID == currentWidget.ArticleTypeID || m.ParentID == currentWidget.ArticleTypeID).Select(m => m.ID).ToList(); if (ids.Any()) { filter = m => m.IsPublish && ids.Contains(m.ArticleTypeID ?? 0); } else { filter = m => m.IsPublish && m.ArticleTypeID == currentWidget.ArticleTypeID; } } if (currentWidget.IsPageable) { articles = _articleService.Get(filter, pagin).ToList(); } else { articles = _articleService.Get(filter).OrderByDescending(m => m.PublishDate).ToList(); } var currentArticleType = _articleTypeService.Get(cate == 0 ? currentWidget.ArticleTypeID : cate); if (currentArticleType != null) { var page = actionContext.HttpContext.GetLayout().Page; page.Title = (page.Title ?? "") + " - " + currentArticleType.Title; } return(widget.ToWidgetViewModelPart(new ArticleListWidgetViewModel { Articles = articles, Widget = currentWidget, Pagin = pagin, CategoryTitle = categoryEntity == null ? "" : categoryEntity.Title, IsPageable = currentWidget.IsPageable })); }
public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { ArticleTypeWidget currentWidget = widget as ArticleTypeWidget; var types = _articleTypeService.Get(m => m.ParentID == currentWidget.ArticleTypeID); int ac = actionContext.RouteData.GetCategory(); return(widget.ToWidgetViewModelPart(new ArticleTypeWidgetViewModel { ArticleTypes = types, CurrentType = _articleTypeService.Get(currentWidget.ArticleTypeID), TargetPage = currentWidget.TargetPage.IsNullOrEmpty() ? actionContext.HttpContext.Request.Path.ToString().ToLower() : currentWidget.TargetPage, ArticleTypeID = ac })); }
private ServiceResult <ArticleType> ValidParentId(ArticleType articleType) { ServiceResult <ArticleType> result = new ServiceResult <ArticleType>(); if (articleType.ParentID.HasValue) { var parentArticleType = _articleTypeService.Get(articleType.ParentID.Value); if (parentArticleType == null) { result.AddRuleViolation("ParentID", "Parent is not exist"); } } return(result); }
public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { var currentWidget = widget as ArticleListWidget; var categoryEntity = _articleTypeService.Get(currentWidget.ArticleTypeID); int pageIndex = actionContext.RouteData.GetPage(); int cate = actionContext.RouteData.GetCategory(); var page = new Pagination { PageIndex = pageIndex, PageSize = currentWidget.PageSize ?? 20 }; IEnumerable <ArticleEntity> articles; Expression <Func <ArticleEntity, bool> > filter = null; if (cate != 0) { filter = m => m.IsPublish && m.ArticleTypeID == cate; } else { var ids = _articleTypeService.Get(m => m.ID == currentWidget.ArticleTypeID || m.ParentID == currentWidget.ArticleTypeID).Select(m => m.ID); if (ids.Any()) { filter = m => m.IsPublish && ids.Any(id => id == m.ArticleTypeID); } else { filter = m => m.IsPublish && m.ArticleTypeID == currentWidget.ArticleTypeID; } } if (currentWidget.IsPageable) { page.RecordCount = _articleService.Count(filter); articles = _articleService.Get(filter).OrderByDescending(m => m.ID).Skip(page.PageIndex * page.PageSize).Take(page.PageSize);; } else { articles = _articleService.Get(filter).OrderByDescending(m => m.ID); } return(widget.ToWidgetViewModelPart(new ArticleListWidgetViewModel { Articles = articles, Widget = currentWidget, Pagin = page, CategoryTitle = categoryEntity == null ? "" : categoryEntity.Title, IsPageable = currentWidget.IsPageable })); }
public IEnumerable <SiteUrl> Get() { List <string> excuted = new List <string>(); foreach (var item in _sitemapDbContext.ArticleListWidget.ToList()) { if (!excuted.Contains(item.DetailPageUrl)) { var ids = _articleTypeService.Get(m => m.ID == item.ArticleTypeID || m.ParentID == item.ArticleTypeID).Select(m => m.ID).ToList(); var articles = _articleService.Get(m => m.IsPublish && ids.Contains(m.ArticleTypeID ?? 0)); foreach (var article in articles) { string post = article.Url.IsNullOrWhiteSpace() ? $"post-{article.ID}" : article.Url; yield return(new SiteUrl { Url = $"{item.DetailPageUrl.Replace("~/", "/")}/{post}.html", ModifyDate = article.LastUpdateDate ?? DateTime.Now, Changefreq = "daily", Priority = 0.5F }); } excuted.Add(item.DetailPageUrl); } } }
public IEnumerable <SiteUrl> Get() { string host = _httpContextAccessor.HttpContext.Request.Scheme + "://" + _httpContextAccessor.HttpContext.Request.Host + "/"; List <string> excuted = new List <string>(); foreach (var item in _sitemapDbContext.ArticleListWidget.ToList()) { if (!excuted.Contains(item.DetailPageUrl)) { var ids = _articleTypeService.Get(m => m.ID == item.ArticleTypeID || m.ParentID == item.ArticleTypeID).Select(m => m.ID).ToList(); var articles = _articleService.Get(m => m.IsPublish && ids.Contains(m.ArticleTypeID ?? 0)); foreach (var article in articles) { yield return(new SiteUrl { Url = item.DetailPageUrl.Replace("~/", host) + "/post-" + $"{article.ID}.html", ModifyDate = article.LastUpdateDate ?? DateTime.Now, Changefreq = "daily", Priority = 0.5F }); } excuted.Add(item.DetailPageUrl); } } }
public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { var currentWidget = widget as ArticleTopWidget; var viewModel = new ArticleTopWidgetViewModel { Widget = currentWidget }; var categoryIds = _articleTypeService.Get(m => m.ID == currentWidget.ArticleTypeID || m.ParentID == currentWidget.ArticleTypeID).Select(m => m.ID); viewModel.Articles = _articleService.Get(m => m.IsPublish && categoryIds.Any(cate => cate == m.ArticleTypeID)).OrderByDescending(m => m.PublishDate).Take(currentWidget.Tops ?? 10); return(widget.ToWidgetViewModelPart(viewModel)); }
public override object Display(WidgetDisplayContext widgetDisplayContext) { var currentWidget = widgetDisplayContext.Widget as ArticleTopWidget; var viewModel = new ArticleTopWidgetViewModel { Widget = currentWidget }; var categoryIds = _articleTypeService.Get(m => m.ID == currentWidget.ArticleTypeID || m.ParentID == currentWidget.ArticleTypeID).Select(m => m.ID); viewModel.Articles = _articleService.Get(m => m.IsPublish && categoryIds.Contains(m.ArticleTypeID ?? 0)).OrderByDescending(m => m.PublishDate).Take(currentWidget.Tops ?? 10); return(viewModel); }
public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { ArticleTypeWidget currentWidget = widget as ArticleTypeWidget; var types = _articleTypeService.Get(m => m.ParentID == currentWidget.ArticleTypeID); int ac = actionContext.RouteData.GetCategory(); if (actionContext.RouteData.GetCategoryUrl().IsNullOrEmpty() && ac > 0) { var articleType = _articleTypeService.Get(ac); if (articleType != null && articleType.Url.IsNotNullAndWhiteSpace()) { actionContext.RedirectTo($"{actionContext.RouteData.GetPath()}/{articleType.Url}", true); } } return(widget.ToWidgetViewModelPart(new ArticleTypeWidgetViewModel { ArticleTypes = types, ArticleTypeID = ac })); }
private ServiceResult <ArticleEntity> ValidArticleType(ArticleEntity article) { ServiceResult <ArticleEntity> serviceResult = new ServiceResult <ArticleEntity>(); ArticleType articleType = _articleTypeService.Get(article.ArticleTypeID ?? 0); if (articleType == null) { serviceResult.AddRuleViolation("ArticleTypeID", "Article type is not exist."); return(serviceResult); } return(serviceResult); }
public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext) { ArticleTypeWidget currentWidget = widget as ArticleTypeWidget; var types = _articleTypeService.Get(m => m.ParentID == currentWidget.ArticleTypeID); int ac = actionContext.RouteData.GetCategory(); return(widget.ToWidgetViewModelPart(new ArticleTypeWidgetViewModel { ArticleTypes = types, ArticleTypeID = ac })); }
public IEnumerable <ArticleUrl> GetAllPublicUrls() { HashSet <string> excuted = new HashSet <string>(); foreach (var item in _articleListWidgetService.Get().ToList()) { string typeDetail = $"{item.DetailPageUrl}-{item.ArticleTypeID}"; if (item.DetailPageUrl.IsNotNullAndWhiteSpace() && !excuted.Contains(typeDetail)) { var ids = _articleTypeService.Get(m => m.ID == item.ArticleTypeID || m.ParentID == item.ArticleTypeID).Select(m => m.ID).ToList(); var articles = _articleService.Get(m => m.IsPublish && ids.Contains(m.ArticleTypeID ?? 0)); foreach (var article in articles) { string post = article.Url.IsNullOrWhiteSpace() ? $"post-{article.ID}" : article.Url; yield return(new ArticleUrl { Url = Helper.Url.ToVirtualPath($"{item.DetailPageUrl}/{post}.html"), Article = article }); } excuted.Add(typeDetail); } } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { _articleTypeService = _articleTypeService ?? ServiceLocator.Current.GetInstance <IArticleTypeService>(); filterContext.Controller.ViewData[ViewDataKeys.ArticleCategory] = new SelectList(_articleTypeService.Get(), "ID", "Title"); }