コード例 #1
0
        /// <summary>
        /// 贴吧所在呈现区域拥有者自动创建贴吧事件
        /// </summary>
        /// <param name="sender">群组实体</param>
        /// <param name="eventArgs">事件参数</param>
        void AutoMaintainBarSectionModule_After(GroupEntity sender, CommonEventArgs eventArgs)
        {
            BarSectionService barSectionService = new BarSectionService();

            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                BarSection barSection = BarSection.New();

                barSection.TenantTypeId         = TenantTypeIds.Instance().Group();
                barSection.SectionId            = sender.GroupId;
                barSection.OwnerId              = sender.GroupId;
                barSection.UserId               = sender.UserId;
                barSection.Name                 = sender.GroupName;
                barSection.IsEnabled            = true;
                barSection.LogoImage            = sender.Logo;
                barSection.ThreadCategoryStatus = ThreadCategoryStatus.NotForceEnabled;
                barSectionService.Create(barSection, sender.UserId, null, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                BarSection barSection = barSectionService.Get(sender.GroupId);
                barSection.UserId    = sender.UserId;
                barSection.Name      = sender.GroupName;
                barSection.LogoImage = sender.Logo;

                IList <long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                BarSection barSection = barSectionService.Get(sender.GroupId);
                barSection.AuditStatus = sender.AuditStatus;
                IList <long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else
            {
                barSectionService.Delete(sender.GroupId);
            }
        }
コード例 #2
0
        public ActionResult EditSection(long?sectionId = null)
        {
            pageResourceManager.InsertTitlePart("帖吧设置");
            if (sectionId.HasValue)
            {
                BarSection section = barSectionService.Get(sectionId ?? 0);
                if (section == null)
                {
                    return(HttpNotFound());
                }
                ViewData["UserId"]         = section.UserId;
                ViewData["ManagerUserIds"] = barSectionService.GetSectionManagers(sectionId ?? 0).Select(n => n.UserId);
                IBarSettingsManager manager  = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         settings = manager.Get();
                ViewData["SectionManagerMaxCount"] = settings.SectionManagerMaxCount;

                BarSectionEditModel    model      = section.AsEditModel();
                IEnumerable <Category> categories = categoryService.GetCategoriesOfItem(section.SectionId, 0, TenantTypeIds.Instance().BarSection());
                if (categories != null && categories.Count() > 0)
                {
                    model.CategoryId = categories.ElementAt(0).CategoryId;
                }

                return(View(model));
            }
            else
            {
                ViewData["UserId"] = UserContext.CurrentUser.UserId;
            }
            return(View(new BarSectionEditModel()));
        }
コード例 #3
0
        public ActionResult Detail(string spaceKey, long threadId, int pageIndex = 1, bool onlyLandlord = false, SortBy_BarPost sortBy = SortBy_BarPost.DateCreated, long?postId = null, long?childPostIndex = null)
        {
            BarThread barThread = barThreadService.Get(threadId);

            if (barThread == null)
            {
                return(HttpNotFound());
            }

            GroupEntity group = groupService.Get(spaceKey);

            if (group == null)
            {
                return(HttpNotFound());
            }
            BarSection section = barSectionService.Get(barThread.SectionId);

            if (section == null || section.TenantTypeId != TenantTypeIds.Instance().Group())
            {
                return(HttpNotFound());
            }

            //验证是否通过审核
            long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey);

            if (!authorizer.IsAdministrator(BarConfig.Instance().ApplicationId) && barThread.UserId != currentSpaceUserId &&
                (int)barThread.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(BarConfig.Instance().ApplicationId)))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "尚未通过审核",
                    Body = "由于当前帖子尚未通过审核,您无法浏览当前内容。",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }


            pageResourceManager.InsertTitlePart(section.Name);
            pageResourceManager.InsertTitlePart(barThread.Subject);

            Category category = categoryService.Get(barThread.CategoryId ?? 0);
            string   keyWords = string.Join(",", barThread.TagNames);

            pageResourceManager.SetMetaOfKeywords(category != null ? category.CategoryName + "," + keyWords : keyWords); //设置Keyords类型的Meta
            pageResourceManager.SetMetaOfDescription(HtmlUtility.TrimHtml(barThread.GetResolvedBody(), 120));            //设置Description类型的Meta

            ViewData["EnableRating"] = barSettings.EnableRating;

            //更新浏览计数
            CountService countService = new CountService(TenantTypeIds.Instance().BarThread());

            countService.ChangeCount(CountTypes.Instance().HitTimes(), barThread.ThreadId, barThread.UserId, 1, false);

            PagingDataSet <BarPost> barPosts = barPostService.Gets(threadId, onlyLandlord, sortBy, pageIndex);

            if (pageIndex > barPosts.PageCount && pageIndex > 1)
            {
                return(Detail(spaceKey, threadId, barPosts.PageCount));
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView("~/Applications/Bar/Views/Bar/_ListPost.cshtml", barPosts));
            }

            ViewData["barThread"] = barThread;
            ViewData["group"]     = group;
            return(View(barPosts));
        }
コード例 #4
0
ファイル: BarSearcher.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 微博分页搜索
        /// </summary>
        /// <param name="query">搜索条件</param>
        /// <returns>符合搜索条件的分页集合</returns>
        public PagingDataSet <BarEntity> Search(BarFullTextQuery barQuery)
        {
            if (string.IsNullOrWhiteSpace(barQuery.Keyword))
            {
                return(new PagingDataSet <BarEntity>(new List <BarEntity>()));
            }

            LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(barQuery);

            //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort
            Query  query  = null;
            Filter filter = null;
            Sort   sort   = null;

            searchBuilder.BuildQuery(out query, out filter, out sort);

            //调用SearchService.Search(),执行搜索
            PagingDataSet <Document> searchResult = searchEngine.Search(query, filter, sort, barQuery.PageIndex, barQuery.PageSize);
            IEnumerable <Document>   docs         = searchResult.ToList <Document>();

            //解析出搜索结果中的发帖ID
            List <long> barthreadIds = new List <long>();
            //解析出搜索结果中的回帖ID
            List <long> barpostIds = new List <long>();
            //获取索引中发帖的标签
            Dictionary <long, List <string> > barTags = new Dictionary <long, List <string> >();
            //获取帖吧名
            Dictionary <long, string> barSectionNames = new Dictionary <long, string>();
            //获取索引中回帖的标题
            Dictionary <long, string> barPostSubjects = new Dictionary <long, string>();

            foreach (Document doc in docs)
            {
                //是回帖
                if (doc.Get(BarIndexDocument.IsPost) == "1")
                {
                    long postId = long.Parse(doc.Get(BarIndexDocument.PostId));
                    barpostIds.Add(postId);
                    string subject = doc.Get(BarIndexDocument.Subject);
                    barPostSubjects[postId] = subject;
                }
                else
                {
                    long threadId = long.Parse(doc.Get(BarIndexDocument.ThreadId));
                    barthreadIds.Add(threadId);
                    //if (!string.IsNullOrWhiteSpace(doc.Get(BarIndexDocument.Tag)))
                    //{
                    barTags[threadId] = doc.GetValues(BarIndexDocument.Tag).ToList <string>();
                    //}
                }
                long sectionId = long.Parse(doc.Get(BarIndexDocument.SectionId));
                if (!barSectionNames.ContainsKey(sectionId))
                {
                    string sectionName = barSectionService.Get(sectionId).Name;
                    barSectionNames[sectionId] = sectionName;
                }
            }

            //根据发帖ID列表批量查询发帖实例
            IEnumerable <BarThread> barThreadList = barThreadService.GetBarThreads(barthreadIds);
            //根据回帖ID列表批量查询回帖实例
            IEnumerable <BarPost> barPostList = barPostService.GetBarPosts(barpostIds);



            //组装帖子列表
            List <BarEntity> barEntityList = new List <BarEntity>();

            foreach (var barThread in barThreadList)
            {
                BarEntity barEntity = new BarEntity();
                barEntity.SectionId = barThread.SectionId;
                barEntity.ThreadId  = barThread.ThreadId;
                barEntity.PostId    = 0;
                barEntity.Subject   = barThread.Subject;
                barEntity.Body      = barThread.GetBody();
                barEntity.UserId    = barThread.UserId;
                barEntity.Author    = barThread.Author;
                if (barTags.Keys.Contains(barEntity.ThreadId))
                {
                    barEntity.Tag = barTags.Count == 0 ? new List <string>() : barTags[barEntity.ThreadId];
                }
                else
                {
                    barEntity.Tag = new List <string>();
                }
                if (barSectionNames.Keys.Contains(barEntity.SectionId))
                {
                    barEntity.SectionName = barSectionNames.Count == 0 ? "" : barSectionNames[barEntity.SectionId];
                }
                else
                {
                    barEntity.SectionName = "";
                }
                barEntity.DateCreated = barThread.DateCreated;
                barEntity.IsPost      = false;
                barEntityList.Add(barEntity);
            }
            foreach (var barPost in barPostList)
            {
                BarEntity barEntity = new BarEntity();
                barEntity.SectionId = barPost.SectionId;
                barEntity.ThreadId  = barPost.ThreadId;
                barEntity.PostId    = barPost.PostId;
                barEntity.Subject   = barPostSubjects[barPost.PostId];
                barEntity.UserId    = barPost.UserId;
                barEntity.Body      = barPost.GetBody();
                barEntity.Author    = barPost.Author;
                barEntity.Tag       = null;
                if (barSectionNames.Keys.Contains(barEntity.SectionId))
                {
                    barEntity.SectionName = barSectionNames.Count == 0 ? "" : barSectionNames[barEntity.SectionId];
                }
                else
                {
                    barEntity.SectionName = "";
                }
                barEntity.DateCreated = barPost.DateCreated;
                barEntity.IsPost      = true;
                barEntityList.Add(barEntity);
            }

            //组装分页对象
            PagingDataSet <BarEntity> barEntities = new PagingDataSet <BarEntity>(barEntityList.OrderByDescending(b => b.DateCreated))
            {
                TotalRecords  = searchResult.TotalRecords,
                PageSize      = searchResult.PageSize,
                PageIndex     = searchResult.PageIndex,
                QueryDuration = searchResult.QueryDuration
            };

            return(barEntities);
        }