public ActionResult ManagePosts(string spaceKey, ManagePostsEditModel model, int pageIndex = 1) { long sectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); BarSection section = barSectionService.Get(sectionId); if (!new Authorizer().BarSection_Manage(section)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "您可能没有权限编辑此帖吧" }))); } var group = groupService.Get(spaceKey); pageResourceManager.InsertTitlePart(group.GroupName); pageResourceManager.InsertTitlePart("回帖管理"); BarPostQuery query = model.AsBarPostQuery(); query.SectionId = section.SectionId; model.SectionId = section.SectionId; ViewData["BarPosts"] = barPostService.Gets(TenantTypeIds.Instance().Group(), query, model.PageSize ?? 20, pageIndex); return(View(model)); }
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); ISettingsManager <BarSettings> manager = DIContainer.Resolve <ISettingsManager <BarSettings> >(); 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())); }
public ActionResult SectionDetail(string spaceKey, long?categoryId = null, bool?isEssential = null, SortBy_BarThread?sortBy = null, bool?isPosted = null, int pageIndex = 1) { IUser currentUser = UserContext.CurrentUser; long sectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); BarSection barSection = barSectionService.Get(sectionId); if (barSection == null) { return(HttpNotFound()); } if (barSection.AuditStatus != AuditStatus.Success && !new Authorizer().BarSection_Manage(barSection)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "此群组还未通过审核,不能查看", StatusMessageType = StatusMessageType.Error }))); } PagingDataSet <BarThread> pds = barThreadService.Gets(sectionId, categoryId, isEssential, sortBy ?? SortBy_BarThread.LastModified_Desc, pageIndex); if (Request.IsAjaxRequest()) { return(PartialView("~/Applications/Bar/Views/Bar/_List.cshtml", pds)); } pageResourceManager.InsertTitlePart(barSection.Name); Category currentThreadCategory = null; if (categoryId.HasValue && categoryId.Value > 0) { currentThreadCategory = categoryService.Get(categoryId.Value); } if (currentThreadCategory != null) { ViewData["currentThreadCategory"] = currentThreadCategory; } //若当前用户是在浏览自己的帖子列表,或者是管理员,则忽略审核; bool ignoreAudit = currentUser != null && UserContext.CurrentUser.UserId == currentUser.UserId || new Authorizer().IsAdministrator(BarConfig.Instance().ApplicationId); if (isPosted.HasValue) { pds = barThreadService.GetUserThreads(TenantTypeIds.Instance().Group(), currentUser.UserId, ignoreAudit, isPosted.Value, pageIndex, sectionId); } ViewData["section"] = barSection; ViewData["threadCategories"] = categoryService.GetOwnerCategories(sectionId, TenantTypeIds.Instance().BarThread()); ViewData["sortBy"] = sortBy; return(View(pds)); }
/// <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); } }
public ActionResult ManageThreads(string spaceKey, ManageThreadEditModel model, int pageIndex = 1) { long groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); BarSection section = barSectionService.Get(groupId); if (!new Authorizer().BarSection_Manage(section)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = string.Format("您没有权限管理 {0} !", section == null ? "" : section.Name), Title = "没有权限", StatusMessageType = StatusMessageType.Error }))); } var group = groupService.Get(spaceKey); pageResourceManager.InsertTitlePart(group.GroupName); pageResourceManager.InsertTitlePart("帖吧管理"); List <SelectListItem> SelectListItem_TrueAndFlase = new List <SelectListItem> { new SelectListItem { Text = "是", Value = true.ToString() }, new SelectListItem { Text = "否", Value = false.ToString() } }; ViewData["IsEssential"] = new SelectList(SelectListItem_TrueAndFlase, "Value", "Text", model.IsEssential); ViewData["IsSticky"] = new SelectList(SelectListItem_TrueAndFlase, "Value", "Text", model.IsSticky); IEnumerable <Category> categories = categoryService.GetOwnerCategories(section.SectionId, TenantTypeIds.Instance().BarThread()); ViewData["CategoryId"] = new SelectList(categories.Select(n => new { text = StringUtility.Trim(n.CategoryName, 20), value = n.CategoryId }), "value", "text", model.CategoryId); BarThreadQuery query = model.GetBarThreadQuery(); query.SectionId = section.SectionId; ViewData["BarThreads"] = barThreadService.Gets(TenantTypeIds.Instance().Group(), query, model.PageSize ?? 20, pageIndex); model.SectionId = section.SectionId; ViewData["TenantType"] = new TenantTypeService().Get(TenantTypeIds.Instance().Group()); return(View(model)); }
/// <summary> /// 帖吧申请处理结果通知 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void BarSectionNoticeEventModule_After(BarSection sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { IUserService userService = DIContainer.Resolve <IUserService>(); NoticeService noticeService = DIContainer.Resolve <NoticeService>(); User toUser = userService.GetFullUser(sender.UserId); if (toUser == null) { return; } Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = toUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(toUser.UserName)); notice.RelativeObjectId = sender.SectionId; notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Name, 64); if (eventArgs.EventOperationType == EventOperationType.Instance().Approved()) { //通知吧主,其申请的帖吧通过了审核 notice.TemplateName = NoticeTemplateNames.Instance().ManagerApproved(); } else { //通知吧主,其申请的帖吧未通过审核 notice.TemplateName = NoticeTemplateNames.Instance().ManagerDisapproved(); } notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SectionDetail(sender.SectionId)); noticeService.Create(notice); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); IEnumerable <long> userIds = subscribeService.GetTopUserIdsOfObject(sender.SectionId, int.MaxValue); foreach (long userId in userIds) { subscribeService.CancelSubscribe(sender.SectionId, userId); } } }
/// <summary> /// 贴吧操作日志事件处理 /// </summary> private void BarSectionOperationLogEventModule_After(BarSection senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().SetSticky() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelSticky()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = BarConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = senders.Name; entry.OperationObjectId = senders.SectionId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "贴吧", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 贴吧操作日志事件处理 /// </summary> private void BarSectionOperationLogEventModule_After(BarSection senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().SetSticky() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelSticky()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = BarConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = senders.Name; entry.OperationObjectId = senders.SectionId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "贴吧", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 群组内搜索帖子 /// </summary> /// <param name="spaceKey">群组名</param> /// <param name="keyword">关键字</param> /// <param name="pageIndex">页码</param> /// <returns>群组内搜索帖子</returns> public ActionResult Search(string spaceKey, string keyword, BarSearchRange term = BarSearchRange.ALL, int pageIndex = 1) { long barSectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); var group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } ViewData["group"] = group; BarSection section = barSectionService.Get(barSectionId); if (section == null) { return(HttpNotFound()); } ViewData["section"] = section; BarFullTextQuery query = new BarFullTextQuery(); query.Term = term; query.PageIndex = pageIndex; query.PageSize = 20;//每页记录数 query.Keyword = keyword; query.Range = section.SectionId.ToString(); //获取群组贴吧的帖子 query.TenantTypeId = TenantTypeIds.Instance().Group(); //根据帖吧id查询帖吧名字 query.TenantTypeId = section.TenantTypeId; ViewData["barname"] = section.Name; ViewData["TenantTypeId"] = section.TenantTypeId; //调用搜索器进行搜索 BarSearcher BarSearcher = (BarSearcher)SearcherFactory.GetSearcher(BarSearcher.CODE); PagingDataSet <BarEntity> BarEntities = BarSearcher.Search(query); if (Request.IsAjaxRequest()) { return(View("~/Applications/Bar/Views/Bar/_ListSearchThread.cshtml", BarEntities)); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("群组帖子搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关帖子");//设置页面Title } pageResourceManager.SetMetaOfKeywords("帖吧搜索"); //设置Keyords类型的Meta pageResourceManager.SetMetaOfDescription("帖吧搜索"); //设置Description类型的Meta return(View(BarEntities)); }
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)); }
public ActionResult Edit(string spaceKey, long?threadId) { long sectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); BarSection section = barSectionService.Get(sectionId); if (UserContext.CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } if (section == null) { return(HttpNotFound()); } GroupEntity group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } pageResourceManager.InsertTitlePart(section.Name); BarThread barThread = threadId.HasValue ? barThreadService.Get(threadId ?? 0) : null; if (threadId.HasValue) { if (!new Authorizer().BarThread_Edit(barThread)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有权限编辑" + barThread.Subject + "!", Title = "没有权限", StatusMessageType = StatusMessageType.Error }))); } } else { string errorMessage = string.Empty; if (!new Authorizer().BarThread_Create(sectionId, out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Error }, Request.RawUrl))); } } pageResourceManager.InsertTitlePart(threadId.HasValue ? "编辑帖子" : "发帖"); if (threadId.HasValue && barThread == null) { return(HttpNotFound()); } ViewData["barSettings"] = barSettings; ViewData["group"] = group; ViewData["BarSection"] = section; return(View("Edit", barThread == null ? new BarThreadEditModel { SectionId = sectionId } : barThread.AsEditModel())); }
public ActionResult EditSection(BarSectionEditModel model) { HttpPostedFileBase logoImage = Request.Files["LogoImage"]; string logoImageFileName = string.Empty; Stream stream = null; if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().BarSection()); if (!tenantLogoSettings.ValidateFileLength(logoImage.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("Logo文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return(View(model)); } LogoSettings logoSettings = DIContainer.Resolve <ISettingsManager <LogoSettings> >().Get(); if (!logoSettings.ValidateFileExtensions(logoImage.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "Logo文件是不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return(View(model)); } stream = logoImage.InputStream; logoImageFileName = logoImage.FileName; } IEnumerable <long> managerUserIds = Request.Form.Gets <long>("ManagerUserIds"); if (model.SectionId == 0) { BarSection section = model.AsBarSection(); //long userId = Request.QueryString.Gets<long>(model.UserId, new List<long>()).FirstOrDefault(); section.UserId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault(); if (section.UserId == 0) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请输入吧主信息"); return(View(model)); } section.LogoImage = logoImageFileName; section.DisplayOrder = model.DisplayOrder ?? 100; if (managerUserIds != null && managerUserIds.Count() > 0) { managerUserIds = managerUserIds.Where(n => n != section.UserId); } bool isCreated = barSectionService.Create(section, UserContext.CurrentUser.UserId, managerUserIds, stream); categoryService.AddItemsToCategory(new List <long> { section.SectionId }, model.CategoryId); if (isCreated) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功"); return(Redirect(SiteUrls.Instance().EditSection(section.SectionId))); } ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建失败"); return(View(model)); } else { BarSection section = model.AsBarSection(); long userId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault(); if (userId == 0) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "必须输入吧主信息"); ViewData["ManagerUserIds"] = barSectionService.GetSectionManagers(section.SectionId).Select(n => n.UserId); ISettingsManager <BarSettings> manager = DIContainer.Resolve <ISettingsManager <BarSettings> >(); BarSettings settings = manager.Get(); ViewData["SectionManagerMaxCount"] = settings.SectionManagerMaxCount; return(View(model)); } section.UserId = userId; if (!string.IsNullOrEmpty(logoImageFileName)) { section.LogoImage = logoImageFileName; } section.DisplayOrder = model.DisplayOrder ?? 100; barSectionService.Update(section, UserContext.CurrentUser.UserId, managerUserIds, stream); categoryService.ClearCategoriesFromItem(section.SectionId, 0, TenantTypeIds.Instance().BarSection()); categoryService.AddItemsToCategory(new List <long> { section.SectionId }, model.CategoryId); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); return(Redirect(SiteUrls.Instance().EditSection(model.SectionId))); } }
/// <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)) { BarSection barSection = barSectionService.Get(sectionId); if (barSection != null) { 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); }
public BarWidgetContext(BarSection section, IMonitor monitor, IConfigContext context) { _section = section; Monitor = monitor; _context = context; }