Пример #1
0
        public override WidgetPart Display(WidgetBase widget, HttpContextBase httpContext)
        {
            var currentWidget      = widget as ArticleListWidget;
            var articleTypeService = new ArticleTypeService();
            var categoryEntity     = articleTypeService.Get(currentWidget.ArticleCategoryID);
            int pageIndex          = 0;
            int ac = 0;

            int.TryParse(httpContext.Request.QueryString["ac"], out ac);
            int.TryParse(httpContext.Request.QueryString["p"], out pageIndex);
            var filter = new Data.DataFilter();

            filter.Where("IsPublish=true");
            filter.OrderBy("PublishDate", OrderType.Descending);
            var articleService = new ArticleService();
            var page           = new Data.Pagination {
                PageIndex = pageIndex, PageSize = currentWidget.PageSize ?? 20
            };

            if (ac != 0)
            {
                filter.Where("ArticleCategoryID", OperatorType.Equal, ac);
            }
            else if (currentWidget.ArticleCategoryID.HasValue)
            {
                filter.Where("ArticleCategoryID", OperatorType.Equal, currentWidget.ArticleCategoryID);
            }
            return(widget.ToWidgetPart(new ArticleListWidgetViewModel
            {
                Articles = currentWidget.IsPageable ? articleService.Get(filter, page) : articleService.Get(filter),
                Widget = currentWidget,
                Pagin = page,
                CategoryTitle = categoryEntity == null ? "" : categoryEntity.Title,
                IsPageable = currentWidget.IsPageable
            }));
        }