Пример #1
0
 /// <summary>
 /// 获取帖吧列表
 /// </summary>
 /// <remarks>在频道帖吧分类页使用</remarks>
 /// <param name="nameKeyword"></param>
 /// <param name="sortBy">帖吧排序依据</param>
 /// <param name="categoryId">帖吧分类Id</param>
 /// <param name="pageIndex">页码</param>
 /// <returns>帖吧列表</returns>
 public PagingDataSet <BarSection> Gets(string nameKeyword, long?categoryId, SortBy_BarSection sortBy, int pageIndex)
 {
     //需要获取categoryId所有后代的类别下的BarSection
     //按排序序号、创建时间倒序排序
     //缓存周期:相对稳定,需维护即时性
     return(barSectionRepository.Gets(TenantTypeIds.Instance().Bar(), nameKeyword, categoryId, sortBy, pageIndex));
 }
 public ActionResult _TopSections(int topNumber = 10, long? categoryId = null, SortBy_BarSection sortBy = SortBy_BarSection.ThreadAndPostCount, DisplayTemplate_TopSections displayTemplate = DisplayTemplate_TopSections.Headline)
 {
     IEnumerable<BarSection> sections = barSectionService.GetTops(topNumber, categoryId, sortBy);
     if (displayTemplate == DisplayTemplate_TopSections.Headline && sections != null && sections.Count() > 0)
     {
         ViewData["TopThreads"] = barThreadService.Gets(sections.First().SectionId, null, null, SortBy_BarThread.LastModified_Desc, 1).Take(2);
     }
     ViewData["SortBy"] = sortBy;
     return View("_TopSections_" + displayTemplate.ToString(), sections);
 }
        /// <summary>
        /// 帖吧列表
        /// </summary>
        /// <returns></returns>
        public ActionResult ListSections(string nameKeyword, long? categoryId, SortBy_BarSection? sortBy, int pageIndex = 1)
        {
            nameKeyword = WebUtility.UrlDecode(nameKeyword);
            IEnumerable<Category> childCategories = null;
            if (categoryId.HasValue && categoryId.Value > 0)
            {
                var category = categoryService.Get(categoryId.Value);
                if (category != null)
                {
                    if (category.ChildCount == 0) //若是叶子节点,则取同辈分类
                    {
                        if (category.Parent != null)
                            childCategories = category.Parent.Children;
                    }
                    else
                        childCategories = category.Children;
                    List<Category> allParentCategories = new List<Category>();
                    //递归获取所有父级类别,若不是叶子节点,则包含其自身
                    RecursiveGetAllParentCategories(category.ChildCount > 0 ? category : category.Parent, ref allParentCategories);
                    ViewData["allParentCategories"] = allParentCategories;
                    ViewData["currentCategory"] = category;

                    pageResourceManager.InsertTitlePart(category.CategoryName);
                }
            }
            else
                pageResourceManager.InsertTitlePart("浏览帖吧");

            if (childCategories == null)
                childCategories = categoryService.GetRootCategories(TenantTypeIds.Instance().BarSection());

            ViewData["childCategories"] = childCategories;
            PagingDataSet<BarSection> pds = barSectionService.Gets(nameKeyword, categoryId, sortBy ?? SortBy_BarSection.ThreadAndPostCount, pageIndex);
            ViewData["sortBy"] = sortBy;
            ViewData["categoryId"] = categoryId;
            return View(pds);
        }
Пример #4
0
 /// <summary>
 /// 获取帖吧的排行数据(仅显示审核通过的帖吧)
 /// </summary>
 /// <param name="topNumber">前多少条</param>
 /// <param name="categoryId">帖吧分类Id</param>
 /// <param name="sortBy">帖吧排序依据</param>
 /// <returns></returns>
 public IEnumerable<BarSection> GetTops(int topNumber, long? categoryId, SortBy_BarSection sortBy = SortBy_BarSection.DateCreated_Desc)
 {
     //只获取启用状态的帖吧
     //缓存周期:相对稳定,不用维护即时性
     return barSectionRepository.GetTops(TenantTypeIds.Instance().Bar(), topNumber, categoryId, sortBy);
 }
Пример #5
0
 /// <summary>
 /// 获取帖吧列表
 /// </summary>
 /// <remarks>在频道帖吧分类页使用</remarks>
 /// <param name="nameKeyword"></param>
 /// <param name="sortBy">帖吧排序依据</param>
 /// <param name="categoryId">帖吧分类Id</param>
 /// <param name="pageIndex">页码</param>
 /// <returns>帖吧列表</returns>
 public PagingDataSet<BarSection> Gets(string nameKeyword, long? categoryId, SortBy_BarSection sortBy, int pageIndex)
 {
     //需要获取categoryId所有后代的类别下的BarSection
     //按排序序号、创建时间倒序排序
     //缓存周期:相对稳定,需维护即时性
     return barSectionRepository.Gets(TenantTypeIds.Instance().Bar(), nameKeyword, categoryId, sortBy, pageIndex);
 }
Пример #6
0
        /// <summary>
        /// 获取类别下帖吧列表的SQL块
        /// </summary>
        /// <param name="tenantTypeId"></param>
        /// <param name="nameKeyword"></param>
        /// <param name="categoryId"></param>
        /// <param name="sortBy"></param>
        /// <returns></returns>
        private Sql GetSql_SectionsByCategoryId(string tenantTypeId, string nameKeyword, long?categoryId, SortBy_BarSection sortBy)
        {
            var sql      = Sql.Builder;
            var whereSql = Sql.Builder;
            var orderSql = Sql.Builder;

            sql.Select("spb_BarSections.*")
            .From("spb_BarSections");

            whereSql.Where("TenantTypeId = @0", tenantTypeId)
            .Where("AuditStatus=@0", AuditStatus.Success)
            .Where("IsEnabled=@0", true);
            if (!string.IsNullOrEmpty(nameKeyword))
            {
                whereSql.Where("Name like @0", StringUtility.StripSQLInjection(nameKeyword) + "%");
            }
            if (categoryId != null && categoryId.Value > 0)
            {
                CategoryService        categoryService = new CategoryService();
                IEnumerable <Category> categories      = categoryService.GetDescendants(categoryId.Value);
                List <long>            categoryIds     = new List <long> {
                    categoryId.Value
                };
                if (categories != null && categories.Count() > 0)
                {
                    categoryIds.AddRange(categories.Select(n => n.CategoryId));
                }
                sql.InnerJoin("tn_ItemsInCategories")
                .On("spb_BarSections.SectionId = tn_ItemsInCategories.ItemId");
                whereSql.Where("tn_ItemsInCategories.CategoryId in(@categoryIds)", new { categoryIds = categoryIds });
            }
            CountService countService   = new CountService(TenantTypeIds.Instance().BarSection());
            string       countTableName = countService.GetTableName_Counts();

            switch (sortBy)
            {
            case SortBy_BarSection.DateCreated_Desc:
                orderSql.OrderBy("DisplayOrder,SectionId desc");
                break;

            case SortBy_BarSection.ThreadCount:
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().ThreadCount()))
                .On("SectionId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case SortBy_BarSection.ThreadAndPostCount:
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().ThreadAndPostCount()))
                .On("SectionId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case SortBy_BarSection.StageThreadAndPostCount:
                StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().BarSection());
                int    stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().ThreadAndPostCount());
                string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().ThreadAndPostCount(), stageCountDays);
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType))
                .On("SectionId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            case SortBy_BarSection.FollowedCount:
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().FollowedCount()))
                .On("SectionId = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");
                break;

            default:
                orderSql.OrderBy("SectionId desc");
                break;
            }

            sql.Append(whereSql).Append(orderSql);
            return(sql);
        }
Пример #7
0
 /// <summary>
 /// 获取帖吧列表
 /// </summary>
 /// <remarks>在频道帖吧分类页使用</remarks>
 /// <param name="tenantTypeId">租户类型Id</param>
 /// <param name="nameKeyword"></param>
 /// <param name="categoryId">帖吧分类Id</param>
 /// <param name="categoryId">帖吧分类Id</param>
 /// <param name="sortBy">帖吧排序依据</param>
 /// <param name="pageIndex">页码</param>
 /// <returns>帖吧列表</returns>
 public PagingDataSet <BarSection> Gets(string tenantTypeId, string nameKeyword, long?categoryId, SortBy_BarSection sortBy, int pageIndex)
 {
     if (string.IsNullOrEmpty(nameKeyword))
     {
         return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.UsualObjectCollection, () =>
         {
             StringBuilder cacheKey = new StringBuilder();
             cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.None));
             cacheKey.AppendFormat("BarSections::T-{0}:C-{1}:S-{2}", tenantTypeId, categoryId, sortBy);
             return cacheKey.ToString();
         }
                                  , () =>
         {
             return GetSql_SectionsByCategoryId(tenantTypeId, string.Empty, categoryId, sortBy);
         }));
     }
     else
     {
         var sql = GetSql_SectionsByCategoryId(tenantTypeId, nameKeyword, categoryId, sortBy);
         return(GetPagingEntities(pageSize, pageIndex, sql));
     }
 }
Пример #8
0
        /// <summary>
        /// 获取帖吧的排行数据
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="topNumber">前多少条</param>
        /// <param name="categoryId">帖吧分类Id</param>
        /// <param name="sortBy">帖吧排序依据</param>
        /// <returns></returns>
        public IEnumerable <BarSection> GetTops(string tenantTypeId, int topNumber, long?categoryId, SortBy_BarSection sortBy)
        {
            return(GetTopEntities(topNumber, CachingExpirationType.UsualObjectCollection, () =>
            {
                StringBuilder cacheKey = new StringBuilder();


                cacheKey.AppendFormat("BarSectionRanks::T-{0}:C-{1}:S-{2}", tenantTypeId, categoryId, (int)sortBy);
                return cacheKey.ToString();
            }
                                  , () =>
            {
                var sql = GetSql_SectionsByCategoryId(tenantTypeId, string.Empty, categoryId, sortBy);
                return sql;
            }));
        }
Пример #9
0
 /// <summary>
 /// 获取帖吧的排行数据(仅显示审核通过的帖吧)
 /// </summary>
 /// <param name="topNumber">前多少条</param>
 /// <param name="categoryId">帖吧分类Id</param>
 /// <param name="sortBy">帖吧排序依据</param>
 /// <returns></returns>
 public IEnumerable <BarSection> GetTops(int topNumber, long?categoryId, SortBy_BarSection sortBy = SortBy_BarSection.DateCreated_Desc)
 {
     //只获取启用状态的帖吧
     //缓存周期:相对稳定,不用维护即时性
     return(barSectionRepository.GetTops(TenantTypeIds.Instance().Bar(), topNumber, categoryId, sortBy));
 }
Пример #10
0
 /// <summary>
 /// 根据分类显示帖吧列表页
 /// </summary>
 /// <param name="siteUrls"></param>
 /// <param name="categoryId">帖吧的Id</param>
 /// <param name="sortBy">帖吧依据</param>
 /// <returns></returns>
 public static string ListSections(this SiteUrls siteUrls, long? categoryId = null, SortBy_BarSection? sortBy = null, string nameKeyword = null)
 {
     RouteValueDictionary routeValueDictionary = new RouteValueDictionary();
     if (categoryId.HasValue && categoryId.Value > 0)
         routeValueDictionary.Add("categoryId", categoryId);
     if (sortBy.HasValue)
         routeValueDictionary.Add("sortBy", sortBy);
     if (!string.IsNullOrEmpty(nameKeyword))
         routeValueDictionary.Add("nameKeyword", WebUtility.UrlEncode(nameKeyword));
     return CachedUrlHelper.Action("ListSections", "Bar", BarAreaName, routeValueDictionary);
 }