public override void ProcessRequest(HttpContext context) { long attachmentId = context.Request.QueryString.Get<long>("attachmentId", 0); if (attachmentId <= 0) { WebUtility.Return404(context); return; } ContentAttachmentService contentAttachmentService = new ContentAttachmentService(); ContentAttachment attachment = contentAttachmentService.Get(attachmentId); if (attachment == null) { WebUtility.Return404(context); return; } IUser currentUser = UserContext.CurrentUser; //下载计数 CountService countService = new CountService(TenantTypeIds.Instance().ContentAttachment()); countService.ChangeCount(CountTypes.Instance().DownloadCount(), attachment.AttachmentId, attachment.UserId, 1, false); bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true); context.Response.Status = "302 Object Moved"; context.Response.StatusCode = 302; LinktimelinessSettings linktimelinessSettings = DIContainer.Resolve<ISettingsManager<LinktimelinessSettings>>().Get(); string token = Utility.EncryptTokenForAttachmentDownload(linktimelinessSettings.Highlinktimeliness, attachmentId); context.Response.Redirect(SiteUrls.Instance().ContentAttachmentTempUrl(attachment.AttachmentId, token, enableCaching), true); context.Response.Flush(); context.Response.End(); }
public override void ProcessRequest(HttpContext context) { long attachmentId = context.Request.QueryString.Get<long>("attachmentId", 0); if (attachmentId <= 0) { WebUtility.Return404(context); return; } string tenantTypeId = context.Request.QueryString.Get<string>("tenantTypeId", null); if (string.IsNullOrEmpty(tenantTypeId)) { WebUtility.Return404(context); return; } AttachmentService<Attachment> attachmentService = new AttachmentService<Attachment>(tenantTypeId); Attachment attachment = attachmentService.Get(attachmentId); if (attachment == null) { WebUtility.Return404(context); return; } IUser currentUser = UserContext.CurrentUser; //判断是否有附件的购买权限或下载权限,有下载权限肯定有购买权限,目前只有未登录或积分不够时才判定为没有权限 if (!DIContainer.Resolve<Authorizer>().Attachment_Buy(attachment)) { WebUtility.Return403(context); return; } //如果还没有下载权限,则说明积分可以支付附件售价,但是还未购买,则先进行积分交易 if (!DIContainer.Resolve<Authorizer>().Attachment_Download(attachment)) { //积分交易 PointService pointService = new PointService(); pointService.Trade(currentUser.UserId, attachment.UserId, attachment.Price, string.Format("购买附件{0}", attachment.FriendlyFileName), true); } //创建下载记录 AttachmentDownloadService attachmentDownloadService = new AttachmentDownloadService(); attachmentDownloadService.Create(currentUser == null ? 0 : currentUser.UserId, attachment.AttachmentId); //下载计数 CountService countService = new CountService(TenantTypeIds.Instance().Attachment()); countService.ChangeCount(CountTypes.Instance().DownloadCount(), attachment.AttachmentId, attachment.UserId, 1, false); bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true); context.Response.Status = "302 Object Moved"; context.Response.StatusCode = 302; LinktimelinessSettings linktimelinessSettings = DIContainer.Resolve<ISettingsManager<LinktimelinessSettings>>().Get(); string token = Utility.EncryptTokenForAttachmentDownload(linktimelinessSettings.Highlinktimeliness, attachmentId); context.Response.Redirect(SiteUrls.Instance().AttachmentTempUrl(attachment.AttachmentId, tenantTypeId, token, enableCaching), true); context.Response.Flush(); context.Response.End(); }
/// <summary> /// 用户状态菜单控件 /// </summary> /// <param name="spaceKey">空间标识</param> public ActionResult _UserStatus(string spaceKey) { User user = userService.GetUser(spaceKey) as User; CountService countService = new CountService(TenantTypeIds.Instance().User()); int countPerDay = countService.GetStageCount(CountTypes.Instance().HitTimes(), 7, user.UserId); int countAll = countService.Get(CountTypes.Instance().HitTimes(), user.UserId); ViewData["accessedCount"] = countPerDay + "/" + countAll; VisitService visitService = new VisitService(TenantTypeIds.Instance().User()); IEnumerable<Visit> visits = visitService.GetTopMyVisits(user.UserId, 1); if (visits != null && visits.FirstOrDefault() != null) { ViewData["lastVisitDate"] = visits.FirstOrDefault().LastVisitTime.ToFriendlyDate(); } return View(user); }
/// <summary> /// 取消关注帖吧 /// </summary> /// <param name="sectionId"></param> /// <returns></returns> public JsonResult CancelSubscribeSection(long sectionId) { if (UserContext.CurrentUser == null) return Json(new StatusMessageData(StatusMessageType.Error, "必须先登录,才能继续操作")); long userId = UserContext.CurrentUser.UserId; if (!subscribeService.IsSubscribed(sectionId, userId)) return Json(new StatusMessageData(StatusMessageType.Error, "您没有关注过该帖吧")); BarSection barSection = barSectionService.Get(sectionId); if (barSection == null) return Json(new StatusMessageData(StatusMessageType.Error, "找不到要被关注的帖吧")); if (barSection.UserId == userId) return Json(new StatusMessageData(StatusMessageType.Error, "吧主不能取消关注帖吧")); if (barSectionService.IsSectionManager(userId, sectionId)) return Json(new StatusMessageData(StatusMessageType.Error, "吧管理员不能取消关注帖吧")); subscribeService.CancelSubscribe(sectionId, userId); //增加帖吧的被关注数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().FollowedCount(), sectionId, barSection.UserId, -1, true); return Json(new StatusMessageData(StatusMessageType.Success, "取消关注操作成功")); }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Topic(), new TopicTagUrlGetter()); //注册专题计数服务 CountService countService = new CountService(TenantTypeIds.Instance().Topic()); countService.RegisterCounts();//注册计数服务 countService.RegisterCountPerDay();//需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 7); OwnerDataSettings.RegisterStatisticsDataKeys(TenantTypeIds.Instance().User() , OwnerDataKeys.Instance().CreatedTopicCount() , OwnerDataKeys.Instance().JoinedTopicCount()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(applicationId, new List<string> { "TopicAdministrator" }); }
/// <summary> /// 创建帖吧 /// </summary> /// <param name="section">帖吧</param> /// <param name="userId">当前操作人</param> /// <param name="managerIds">管理员用户Id</param> /// <param name="logoFile">帖吧标识图</param> /// <returns>是否创建成功</returns> public bool Create(BarSection section, long userId, IEnumerable<long> managerIds, Stream logoFile) { EventBus<BarSection>.Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(userId, section); if (!(section.SectionId > 0)) section.SectionId = IdGenerator.Next(); long id = 0; long.TryParse(barSectionRepository.Insert(section).ToString(), out id); if (id > 0) { if (managerIds != null && managerIds.Count() > 0) { List<long> mangagerIds_list = managerIds.ToList(); mangagerIds_list.Remove(section.UserId); managerIds = mangagerIds_list; barSectionRepository.UpdateManagerIds(id, managerIds); } if (section.TenantTypeId == TenantTypeIds.Instance().Bar()) { //帖吧主、吧管理员自动关注本帖吧 SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); int followedCount = 0; bool result = subscribeService.Subscribe(section.SectionId, section.UserId); if (result) followedCount++; if (managerIds != null && managerIds.Count() > 0) foreach (var managerId in managerIds) { result = subscribeService.Subscribe(section.SectionId, managerId); if (result) followedCount++; } //增加帖吧的被关注数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true); } //上传Logo if (logoFile != null) { LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection()); section.LogoImage = logoService.UploadLogo(section.SectionId, logoFile); barSectionRepository.Update(section); } EventBus<BarSection>.Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus<BarSection, AuditEventArgs>.Instance().OnAfter(section, new AuditEventArgs(section.AuditStatus, null)); } return id > 0; }
/// <summary> /// 删除搜索词 /// </summary> /// <param name="id">搜索词Id</param> public void Delete(long id) { searchedTermRepository.DeleteByEntityId(id); CountService countService = new CountService(TenantTypeIds.Instance().Search()); countService.Delete(id); }
/// <summary> /// 公告详细页 /// </summary> /// <param name="announcementId">公告Id</param> /// <returns>公告实体</returns> public ActionResult AnnouncementDetail(long announcementId) { pageResourceManager.InsertTitlePart("公告"); Announcement announcement = announcementService.Get(announcementId); announcement.UserName = userService.GetUser(announcement.UserId).DisplayName; announcement.IsAdministrator = authorizer.IsAdministrator(0); CountService countService = new CountService(TenantTypeIds.Instance().Announcement()); countService.ChangeCount(CountTypes.Instance().HitTimes(), announcementId, announcement.UserId, 1, false); return View(announcement); }
/// <summary> /// 创建主题帖 /// </summary> /// <param name="thread">主题帖</param> public bool Create(BarThread thread) { BarSectionService barSectionService = new BarSectionService(); EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(thread.UserId, thread); long id = 0; long.TryParse(barThreadRepository.Insert(thread).ToString(), out id); if (id > 0) { new AttachmentService(TenantTypeIds.Instance().BarThread()).ToggleTemporaryAttachments(thread.UserId, TenantTypeIds.Instance().BarThread(), id); BarSection barSection = barSectionService.Get(thread.SectionId); if (barSection != null) { //计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, 1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true); if (thread.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数+1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), 1); } } if (thread.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BarThread()); atUserService.ResolveBodyForEdit(thread.GetBody(), thread.UserId, thread.ThreadId); EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(null, thread.AuditStatus)); } return id > 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); }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册帖吧计数服务 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.RegisterCounts();//注册计数服务 countService.RegisterCountPerDay();//需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().ThreadAndPostCount(), 1); //注册帖子计数服务 countService = new CountService(TenantTypeIds.Instance().BarThread()); countService.RegisterCounts();//注册计数服务 countService.RegisterCountPerDay();//需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 1, 7); //注册贴吧用户计数服务 List<string> tenantTypeIds = new List<string>() { TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group() }; OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds , OwnerDataKeys.Instance().ThreadCount() , OwnerDataKeys.Instance().PostCount() , OwnerDataKeys.Instance().FollowSectionCount()); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().BarThread(), new BarTagUrlGetter()); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Group(), new BarTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Bar(), new List<string> { "BarAdministrator" }); }
/// <summary> /// 初始化应用程序,加载基础数据 /// </summary> private static void InitializeApplication() { //加载应用 ApplicationService applicationService = DIContainer.Resolve<ApplicationService>(); foreach (var application in applicationService.GetAll()) { if (application.Config == null) continue; application.Config.Load(); } //注册事件处理程序 IEnumerable<IEventMoudle> eventMoudles = DIContainer.Resolve<IEnumerable<IEventMoudle>>(); foreach (var eventMoudle in eventMoudles) { eventMoudle.RegisterEventHandler(); } //注册皮肤选择器 ThemeService.RegisterThemeResolver("Channel", new ChannelThemeResolver()); ThemeService.RegisterThemeResolver("UserSpace", new UserSpaceThemeResolver()); ThemeService.RegisterThemeResolver("ControlPanel", new ControlPanelThemeResolver()); //初始化敏感词过滤 SensitiveWordService service = DIContainer.Resolve<SensitiveWordService>(); IEnumerable<SensitiveWord> words = service.Gets(); if (words != null) { WordFilter.Add(WordFilterTypeIds.Instance().SensitiveWord(), words.ToDictionary(n => n.Word, n => n.Replacement)); } //注册标题图的配置 TenantLogoSettings.RegisterSettings(LogoConfigManager.Instance().GetAllLogoConfigs()); //初始化第三方帐号获取器 ThirdAccountGetterFactory.InitializeAll(); //注册标签URL获取管理器 TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().User(), new UserTagUrlGetter()); //注册请求类型 InvitationType.Register(new InvitationType { Key = InvitationTypeKeys.Instance().InviteFollow(), Name = "求关注", Description = "" }); //注册搜索相关的计数服务 CountService countService = new CountService(TenantTypeIds.Instance().Search()); countService.RegisterCounts(); //注册计数服务 countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().SearchCount(), 7); //阶段计数为:最近7天搜索计数 //注册用户相关的计数服务 CountService userCountService = new CountService(TenantTypeIds.Instance().User()); userCountService.RegisterCounts(); //注册计数服务 userCountService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 userCountService.RegisterStageCount(CountTypes.Instance().ReputationPointsCounts(), 7); //阶段计数为:最近7天威望计数 userCountService.RegisterStageCount(CountTypes.Instance().HitTimes(), 7); //阶段计数为:最近7天浏览计数 //注册标签相关的计数服务 CountService perDayCountService = new CountService(TenantTypeIds.Instance().Tag()); perDayCountService.RegisterCounts(); //注册计数服务 perDayCountService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 perDayCountService.RegisterStageCount(CountTypes.Instance().ItemCounts(), 1, 7); //阶段计数为:最近1,7天讨论次数计数 //注册附件相关的计数服务 CountService attachmentCountService = new CountService(TenantTypeIds.Instance().Attachment()); attachmentCountService.RegisterCounts();//注册计数服务 //注册站点公告相关的计数服务 CountService announcementCountService = new CountService(TenantTypeIds.Instance().Announcement()); announcementCountService.RegisterCounts();//注册计数服务 announcementCountService.RegisterCountPerDay();//需要统计阶段计数时,需注册每日计数服务 announcementCountService.RegisterStageCount(CountTypes.Instance().HitTimes(), 7);//阶段计数为:最近7天浏览计数 //注册邮箱相关计数 CountService emailCountService = new CountService(TenantTypeIds.Instance().Email()); emailCountService.RegisterCounts();//注册计数服务 emailCountService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 emailCountService.RegisterStageCount(CountTypes.Instance().UseCount(), 1); //阶段计数为:最近1,7天讨论次数计数 new EmailService().ReLoadSmtpSettings(); //启动定时任务 TaskSchedulerFactory.GetScheduler().Start(); }
//关于缓存期限: //1、PointItem实体、列表 使用CachingExpirationType.RelativelyStable //2、PointCategory实体、列表 使用CachingExpirationType.RelativelyStable //3、PointRecord实体、列表 使用正常的缓存策略 //4、积分记录的所有积分类型都是0,则不创建 #region 积分变更及记录 /// <summary> /// 依据规则增减积分 /// </summary> /// <param name="userId">增减积分的UserId</param> /// <param name="pointItemKey">积分项目标识</param> /// <param name="description">积分记录描述</param> /// <param name="needPointMessage">是否需要积分提醒</param> public void GenerateByRole(long userId, string pointItemKey, string description, bool needPointMessage = false) { //1、依据pointItemKey查找积分项目,如果未找到则中断执行; PointItem pointItem = GetPointItem(pointItemKey); if (pointItem == null) { return; } if (pointItem.ExperiencePoints == 0 && pointItem.ReputationPoints == 0 && pointItem.TradePoints == 0) { return; } //2、检查用户当日各类积分是否达到限额,如果达到限额则不加积分,如果未达到则更新当日积分限额 Dictionary <string, int> dictionary = pointStatisticRepository.UpdateStatistic(userId, GetPointCategory2PointsDictionary(pointItem)); //如果用户当日各类积分都超出限额,则不产生积分 if (dictionary.Count(n => n.Value != 0) == 0) { return; } //3、按照pointItemKey对应的积分项目,生成积分记录,并对用户积分额进行增减; int experiencePoints = dictionary[PointCategoryKeys.Instance().ExperiencePoints()]; int reputationPoints = dictionary[PointCategoryKeys.Instance().ReputationPoints()]; int tradePoints = dictionary[PointCategoryKeys.Instance().TradePoints()]; int tradePoints2 = 0; int tradePoints3 = 0; int tradePoints4 = 0; if (dictionary.ContainsKey("TradePoints2")) { tradePoints2 = dictionary["TradePoints2"]; } if (dictionary.ContainsKey("TradePoints3")) { tradePoints3 = dictionary["TradePoints3"]; } if (dictionary.ContainsKey("TradePoints4")) { tradePoints4 = dictionary["TradePoints4"]; } PointRecord pointRecord = new PointRecord(userId, pointItem.ItemName, description, experiencePoints, reputationPoints, tradePoints); pointRecord.TradePoints2 = tradePoints2; pointRecord.TradePoints3 = tradePoints3; pointRecord.TradePoints4 = tradePoints4; pointRecordRepository.Insert(pointRecord); IUserService userService = DIContainer.Resolve <IUserService>(); userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints, tradePoints2, tradePoints3, tradePoints4); CountService countService = new CountService(TenantTypeIds.Instance().User()); countService.ChangeCount(CountTypes.Instance().ReputationPointsCounts(), userId, userId, pointRecord.ReputationPoints); //用于积分提醒 if (needPointMessage) { TrackPointRecord(userId, pointRecord); } }
/// <summary> /// 解析内容用于创建话题 /// </summary> /// <param name="body">待解析的内容</param> /// <param name="ownerId">标签拥有者Id</param> /// <param name="associateId">关联项Id</param> /// <param name="tenantTypeId">租户类型Id</param> public void ResolveBodyForEdit(string body, long ownerId, long associateId, string tenantTypeId) { if (!body.Contains("#") || string.IsNullOrEmpty(body)) { return; } Regex rg = new Regex(@"(?<=(?<!\&)(\#)(?!\d\;))[^\#@]*(?=(?<!\&)(\#)(?![0-9]+\;))", RegexOptions.Multiline | RegexOptions.Singleline); Match m = rg.Match(body); if (!m.Success) { return; } IList <string> tagNames = new List <string>(); int i = 0, index = -1; while (m != null) { if (i % 2 == 1) { m = m.NextMatch(); i++; continue; } if (index == m.Index) { break; } index = m.Index; if (!string.IsNullOrEmpty(m.Value) && !tagNames.Contains(m.Value)) { tagNames.Add(m.Value); } else { continue; } m = m.NextMatch(); i++; } if (tagNames.Count > 0) { CountService countService = new CountService(TenantTypeIds.Instance().Tag()); AddTagsToItem(tagNames.ToArray(), ownerId, associateId); Dictionary <string, long> tagNamesWithIds = GetTagNamesWithIdsOfItem(associateId); if (tagNamesWithIds != null) { foreach (KeyValuePair <string, long> pair in tagNamesWithIds) { countService.ChangeCount(CountTypes.Instance().ItemCounts(), pair.Value, ownerId, 1); } } } }
/// <summary> /// 依据规则增减积分 /// </summary> /// <param name="userId">增减积分的UserId</param> /// <param name="pointItemKey">积分项目标识</param> /// <param name="description">积分记录描述</param> /// <param name="needPointMessage">是否需要积分提醒</param> public void GenerateByRole(long userId, string pointItemKey, string description, bool needPointMessage = false) { //1、依据pointItemKey查找积分项目,如果未找到则中断执行; PointItem pointItem = GetPointItem(pointItemKey); if (pointItem == null) return; if (pointItem.ExperiencePoints == 0 && pointItem.ReputationPoints == 0 && pointItem.TradePoints == 0) return; //2、检查用户当日各类积分是否达到限额,如果达到限额则不加积分,如果未达到则更新当日积分限额 Dictionary<string, int> dictionary = pointStatisticRepository.UpdateStatistic(userId, GetPointCategory2PointsDictionary(pointItem)); //如果用户当日各类积分都超出限额,则不产生积分 if (dictionary.Count(n => n.Value != 0) == 0) return; //3、按照pointItemKey对应的积分项目,生成积分记录,并对用户积分额进行增减; int experiencePoints = dictionary[PointCategoryKeys.Instance().ExperiencePoints()]; int reputationPoints = dictionary[PointCategoryKeys.Instance().ReputationPoints()]; int tradePoints = dictionary[PointCategoryKeys.Instance().TradePoints()]; int tradePoints2 = 0; int tradePoints3 = 0; int tradePoints4 = 0; if (dictionary.ContainsKey("TradePoints2")) { tradePoints2 = dictionary["TradePoints2"]; } if (dictionary.ContainsKey("TradePoints3")) { tradePoints3 = dictionary["TradePoints3"]; } if (dictionary.ContainsKey("TradePoints4")) { tradePoints4 = dictionary["TradePoints4"]; } PointRecord pointRecord = new PointRecord(userId, pointItem.ItemName, description, experiencePoints, reputationPoints, tradePoints); pointRecord.TradePoints2 = tradePoints2; pointRecord.TradePoints3 = tradePoints3; pointRecord.TradePoints4 = tradePoints4; pointRecordRepository.Insert(pointRecord); IUserService userService = DIContainer.Resolve<IUserService>(); userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints, tradePoints2, tradePoints3, tradePoints4); CountService countService = new CountService(TenantTypeIds.Instance().User()); countService.ChangeCount(CountTypes.Instance().ReputationPointsCounts(), userId, userId, pointRecord.ReputationPoints); //用于积分提醒 if (needPointMessage) TrackPointRecord(userId, pointRecord); }
/// <summary> /// 删除主题帖 /// </summary> /// <param name="threadId">主题帖Id</param> public void Delete(long threadId) { BarThread thread = barThreadRepository.Get(threadId); if (thread == null) return; EventBus<BarThread>.Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Delete())); BarSectionService barSectionService = new BarSectionService(); BarSection barSection = barSectionService.Get(thread.SectionId); if (barSection != null) { //帖子标签 TagService tagService = new TagService(TenantTypeIds.Instance().BarThread()); tagService.ClearTagsFromItem(threadId, barSection.SectionId); //帖子分类 CategoryService categoryService = new CategoryService(); categoryService.ClearCategoriesFromItem(threadId, barSection.SectionId, TenantTypeIds.Instance().BarThread()); } //删除回帖 BarPostService barPostService = new BarPostService(); barPostService.DeletesByThreadId(threadId); //删除推荐记录 RecommendService recommendService = new RecommendService(); recommendService.Delete(threadId, TenantTypeIds.Instance().BarThread()); int affectCount = barThreadRepository.Delete(thread); if (affectCount > 0) { //更新帖吧的计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, -1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1, true); if (thread.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数-1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), -1); } else if (thread.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), -1); } EventBus<BarThread>.Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus<BarThread, AuditEventArgs>.Instance().OnAfter(thread, new AuditEventArgs(thread.AuditStatus, null)); } //BarThread删除可能影响的: //1、附件 (看到了) //2、BarPost(看到了) //3、BarRating(看到了) //4、相关计数对象(看到了) //5、用户在应用中的数据(看到了) //6、@用户(看到了) }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册日志Rss浏览计数服务 CountService countService = new CountService(TenantTypeIds.Instance().Microblog()); countService.RegisterCounts();//注册计数服务 countService.RegisterCountPerDay();//需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().CommentCount(), 1); //注册微博用户计数服务 List<string> tenantTypeIds = new List<string>() { TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group() }; OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds, OwnerDataKeys.Instance().ThreadCount()); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Microblog(), new MicroblogTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Microblog(), new List<string> { "MicroblogAdministrator" }); }
/// <summary> /// 移动帖子 /// </summary> /// <param name="threadId">要移动帖子的ThreadId</param> /// <param name="moveToSectionId">转移到帖吧的SectionId</param> public void MoveThread(long threadId, long moveToSectionId) { BarThread thread = barThreadRepository.Get(threadId); if (thread.SectionId == moveToSectionId) return; long oldSectionId = thread.SectionId; var barSectionService = new BarSectionService(); var oldSection = barSectionService.Get(oldSectionId); if (oldSection == null) return; var newSection = barSectionService.Get(moveToSectionId); if (newSection == null) return; barThreadRepository.MoveThread(threadId, moveToSectionId); CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), oldSection.SectionId, oldSection.UserId, -1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), oldSection.SectionId, oldSection.UserId, -1, true); countService.ChangeCount(CountTypes.Instance().ThreadCount(), newSection.SectionId, newSection.UserId, 1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), newSection.SectionId, newSection.UserId, 1, true); }
/// <summary> /// 搜索词记录及计数 /// </summary> /// <param name="searchTypeCode">搜索类型编码</param> /// <param name="term">搜索词</param> public void SearchTerm(string searchTypeCode, string term) { long id = searchedTermRepository.InsertOrUpdate(searchTypeCode, term, false); CountService countService = new CountService(TenantTypeIds.Instance().Search()); countService.ChangeCount(CountTypes.Instance().SearchCount(), id, 0, 1, false); }
public ActionResult PrivacyHome(string spaceKey) { IUser currentUser = UserContext.CurrentUser; if (UserContext.CurrentUser == null) return Redirect(SiteUrls.Instance().Login(true)); pageResourceManager.InsertTitlePart("无权访问"); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); ViewData["followedUsers"] = followService.GetTopFollowedUserIds(userId, 30).ToDictionary(n => n, m => userService.GetFullUser(m) == null ? UserIdToUserNameDictionary.GetUserName(m) : userService.GetFullUser(m).DisplayName); ViewData["followerUsers"] = followService.GetFollowerUserIds(userId, Follow_SortBy.LastContent_Desc, 1).ToDictionary(n => n, m => userService.GetFullUser(m) == null ? UserIdToUserNameDictionary.GetUserName(m) : userService.GetFullUser(m).DisplayName); User user = userService.GetFullUser(spaceKey); if (user == null) return HttpNotFound(); CountService countService = new CountService(TenantTypeIds.Instance().User()); int countStageDay = countService.GetStageCount(CountTypes.Instance().HitTimes(), 7, user.UserId); int countAll = countService.Get(CountTypes.Instance().HitTimes(), user.UserId); ViewData["accessedCount"] = countStageDay + "/" + countAll; ViewData["user"] = user; bool seeFollow = false; if (privacyService.Validate(user.UserId, currentUser != null ? currentUser.UserId : 0, PrivacyItemKeys.Instance().InviteFollow())) { seeFollow = true; } ViewData["seeFollow"] = seeFollow; return View(); }
/// <summary> /// 更新帖吧 /// </summary> /// <param name="section">帖吧</param> /// <param name="userId">当前操作人</param> /// <param name="managerIds">管理员用户Id</param> /// <param name="sectionedFile">帖吧标识图</param> public void Update(BarSection section, long userId, IEnumerable<long> managerIds, Stream sectionedFile) { EventBus<BarSection>.Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Update())); //上传Logo if (sectionedFile != null) { LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection()); section.LogoImage = logoService.UploadLogo(section.SectionId, sectionedFile); } auditService.ChangeAuditStatusForUpdate(userId, section); barSectionRepository.Update(section); if (managerIds != null && managerIds.Count() > 0) { List<long> mangagerIds_list = managerIds.ToList(); mangagerIds_list.Remove(section.UserId); managerIds = mangagerIds_list; } barSectionRepository.UpdateManagerIds(section.SectionId, managerIds); if (section.TenantTypeId == TenantTypeIds.Instance().Bar()) { SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); //帖吧主、吧管理员自动关注本帖吧 int followedCount = 0; bool result = subscribeService.Subscribe(section.SectionId, section.UserId); if (result) followedCount++; if (managerIds != null && managerIds.Count() > 0) { foreach (var managerId in managerIds) { result = subscribeService.Subscribe(section.SectionId, managerId); if (result) followedCount++; } } //增加帖吧的被关注数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true); } EventBus<BarSection>.Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Update())); }
public ActionResult SpaceHome(string spaceKey, int? pageIndex, int? applicationId = null) { IUser currentUser = UserContext.CurrentUser; User user = userService.GetFullUser(spaceKey); if (user == null) return HttpNotFound(); ViewData["user"] = user; CountService countService = new CountService(TenantTypeIds.Instance().User()); countService.ChangeCount(CountTypes.Instance().HitTimes(), user.UserId, user.UserId, 1, true); AuthorizationService authorizationService = new AuthorizationService(); #region View中需要的信息 //是否是匿名用户 bool isAnonymousUser = false; if (currentUser == null) isAnonymousUser = true; else if (user.UserId != currentUser.UserId) { visitService.CreateVisit(currentUser.UserId, currentUser.DisplayName, user.UserId, user.DisplayName); } ViewData["isAnonymousUser"] = isAnonymousUser; if (!isAnonymousUser) { ViewData["isSuperAdmin_CurrentUser"] = authorizationService.IsSuperAdministrator(currentUser);//当前用户是否为超级管理员 ViewData["isSuperAdmin_User"] = authorizationService.IsSuperAdministrator(user);//被浏览用户是否为超级管理员 ViewData["isRequestFollow"] = !followService.IsFollowed(user.UserId, currentUser.UserId); //是否需要求关注 } //是否为同一用户 bool isSameUser = false; if (!isAnonymousUser && user.UserId == currentUser.UserId) { isSameUser = true; } ViewData["isSameUser"] = isSameUser; //是否关注和悄悄关注 if (currentUser != null) { FollowEntity entity = followService.Get(currentUser.UserId, user.UserId); if (entity != null) { ViewData["noteName"] = entity.NoteName; } bool isQuietly; bool isFollowed = followService.IsFollowed(currentUser.UserId, user.UserId, out isQuietly); ViewData["isFollowed"] = isFollowed; ViewData["isQuietly"] = isQuietly; if (isFollowed) { IEnumerable<string> groupNames = new List<string>(); followService.IsFollowed(currentUser.UserId, user.UserId, out groupNames); if (groupNames.Count() > 0) ViewData["editGroupShow"] = groupNames.FirstOrDefault(); else ViewData["editGroupShow"] = "编辑分组"; } } //简介显示 string introduction; if (user.Profile == null || !user.Profile.HasIntroduction) { introduction = isSameUser ? "可以在此填写个性简介" : "该用户尚未填写简介"; } else { introduction = user.Profile.Introduction; } ViewData["introduction"] = introduction; //共同关注的内容 if (!isSameUser && currentUser != null) { FollowUserSearcher followUserSearcher = (FollowUserSearcher)SearcherFactory.GetSearcher(FollowUserSearcher.CODE); UserSearcher userSearcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE); IEnumerable<User> sameFollowedUsers = followUserSearcher.SearchInterestedWithFollows(currentUser.UserId, user.UserId); IEnumerable<string> sameTagNames = new List<string>(); IEnumerable<string> sameCompanyNames = new List<string>(); IEnumerable<string> sameSchoolNames = new List<string>(); userSearcher.SearchInterested(currentUser.UserId, user.UserId, out sameTagNames, out sameCompanyNames, out sameSchoolNames); ViewData["sameFollowedUsers"] = sameFollowedUsers; ViewData["sameTagNames"] = sameTagNames; ViewData["sameCompanyNames"] = sameCompanyNames; ViewData["sameSchoolNames"] = sameSchoolNames; } #endregion #region Title pageResourceManager.InsertTitlePart(isSameUser ? "我" : user.DisplayName + "的主页"); #endregion #region 身份认证 List<Identification> identifications = identificationService.GetUserIdentifications(user.UserId); if (identifications.Count() > 0) { ViewData["identificationTypeVisiable"] = true; } #endregion ViewData["applications"] = applicationService.GetAll(true); return View(); }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册文章计数服务 CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); //注册计数服务 countService.RegisterCounts(); //需要统计阶段计数时,需注册每日计数服务 countService.RegisterCountPerDay(); //注册文章浏览计数服务 countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 7); //注册用户计数服务 OwnerDataSettings.RegisterStatisticsDataKeys(TenantTypeIds.Instance().User(), OwnerDataKeys.Instance().ThreadCount()); //标签云中标签的链接 TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().BlogThread(), new BlogTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Blog(), new List<string> { "BlogAdministrator" }); }
/// <summary> /// 资讯详情页 /// </summary> public ActionResult ContentItemDetail(long contentItemId) { ContentItem contentItem = contentItemService.Get(contentItemId); if (contentItem == null || contentItem.User == null) { return HttpNotFound(); } //验证是否通过审核 long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(contentItem.User.UserName); if (!authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId) && contentItem.UserId != currentSpaceUserId && (int)contentItem.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(CmsConfig.Instance().ApplicationId))) return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "尚未通过审核", Body = "由于当前资讯尚未通过审核,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint })); AttachmentService<Attachment> attachmentService = new AttachmentService<Attachment>(TenantTypeIds.Instance().ContentItem()); //更新浏览计数 CountService countService = new CountService(TenantTypeIds.Instance().ContentItem()); countService.ChangeCount(CountTypes.Instance().HitTimes(), contentItem.ContentItemId, contentItem.UserId, 1, true); if (UserContext.CurrentUser != null) { //创建访客记录 VisitService visitService = new VisitService(TenantTypeIds.Instance().ContentItem()); visitService.CreateVisit(UserContext.CurrentUser.UserId, UserContext.CurrentUser.DisplayName, contentItem.ContentItemId, contentItem.Title); } //设置SEO信息 pageResourceManager.InsertTitlePart(contentItem.Title); List<string> keywords = new List<string>(); keywords.AddRange(contentItem.TagNames); string keyword = string.Join(" ", keywords.Distinct()); keyword += " " + string.Join(" ", ClauseScrubber.TitleToKeywords(contentItem.Title)); pageResourceManager.SetMetaOfKeywords(keyword); pageResourceManager.SetMetaOfDescription(contentItem.Summary); return View(contentItem); }
public ActionResult ManageSearchedTerms(int? pageIndex = 1, int pageSize = 20) { CountService countService = new CountService(TenantTypeIds.Instance().Search()); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Search()); IEnumerable<ISearcher> searchers = SearcherFactory.GetDisplaySearchers(); #region 搜索条件 int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().SearchCount()); string countTypeNday = countService.GetStageCountType(CountTypes.Instance().SearchCount(), stageCountDays); string countTypeAll = CountTypes.Instance().SearchCount(); pageResourceManager.InsertTitlePart("管理搜索热词"); string term = Request.QueryString.GetString("term", string.Empty).Trim(); bool isRealtime = false; DateTime? startDate = null; DateTime? endDate = null; if (Request.QueryString.Get<DateTime>("startdate") != DateTime.MinValue) startDate = Request.QueryString.Get<DateTime>("startDate"); if (Request.QueryString.Get<DateTime>("enddate") != DateTime.MinValue) endDate = Request.QueryString.Get<DateTime>("endDate"); if (startDate.HasValue && endDate.HasValue && startDate.Value > endDate.Value) { DateTime? changDate = startDate; startDate = endDate; endDate = changDate; } if (endDate.HasValue) endDate = endDate.Value; #endregion #region 下拉列表 string searchTypeCode = Request.QueryString.GetString("searchTypeCode", string.Empty); Dictionary<string, string> searchTypeDic = new Dictionary<string, string>(); searchTypeDic[SearcherFactory.GlobalSearchCode] = SearcherFactory.GlobalSearchName; foreach (var searcher in searchers) { searchTypeDic[searcher.Code] = searcher.Name; } SelectList selectList = new SelectList(searchTypeDic.Select(n => new { text = n.Value, value = n.Key }), "value", "text", searchTypeCode); ViewData["searchTypeCode"] = selectList; #endregion if (string.IsNullOrEmpty(searchTypeCode)) { isRealtime = true; } ViewData["searchTypeDic"] = searchTypeDic; #region Count IEnumerable<SearchedTerm> manuals = null; if (pageIndex == 1) manuals = termService.GetManuals(searchTypeCode); Dictionary<long, int> countTypeNdayDic = new Dictionary<long, int>(); Dictionary<long, int> countTypeAllDic = new Dictionary<long, int>(); if (manuals != null) { if (!string.IsNullOrEmpty(term)) manuals = manuals.Where(n => Regex.IsMatch(n.Term, "^" + term.Trim())); if (!string.IsNullOrEmpty(searchTypeCode)) manuals = manuals.Where(n => n.SearchTypeCode == searchTypeCode); if (startDate != null) manuals = manuals.Where(n => n.DateCreated >= startDate); if (endDate != null) manuals = manuals.Where(n => n.DateCreated <= endDate); foreach (var item in manuals) { countTypeNdayDic[item.Id] = countService.Get(countTypeNday, item.Id); countTypeAllDic[item.Id] = countService.Get(countTypeAll, item.Id); } } ViewData["manuals"] = manuals; PagingDataSet<SearchedTerm> searchedTerms = termService.Gets(searchTypeCode, term, startDate, endDate, isRealtime, pageSize, pageIndex ?? 1); foreach (var item in searchedTerms) { countTypeNdayDic[item.Id] = countService.Get(countTypeNday, item.Id); countTypeAllDic[item.Id] = countService.Get(countTypeAll, item.Id); } ViewData["countTypeNdayDic"] = countTypeNdayDic; ViewData["countTypeAllDic"] = countTypeAllDic; #endregion return View(searchedTerms); }
/// <summary> /// 删除评论 /// </summary> /// <param name="id">评论Id</param> /// <returns>删除成功返回true,否则返回false</returns> public bool Delete(long id) { Comment comment = commentRepository.Get(id); long parentID = 0; int count = 0; if (comment != null) { //触发事件 EventBus<Comment>.Instance().OnBefore(comment, new CommonEventArgs(EventOperationType.Instance().Delete())); parentID = comment.ParentId; count = commentRepository.Delete(id); if (count > 0) { commentRepository.UpdateChildCount(parentID, true); CountService countService = new CountService(comment.TenantTypeId); countService.ChangeCount(CountTypes.Instance().CommentCount(), comment.CommentedObjectId, comment.OwnerId, -1 - comment.ChildCount, true); //触发事件 EventBus<Comment>.Instance().OnAfter(comment, new CommonEventArgs(EventOperationType.Instance().Delete())); } } return count > 0; }
public ActionResult ThreadDetail(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(); BarSection section = barSectionService.Get(barThread.SectionId); if (!authorizer.BarSection_View(section)) return Redirect(SiteUrls.Instance().SystemMessage(TempData, SystemMessageViewModel.NoCompetence())); 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 ThreadDetail(threadId, barPosts.PageCount); if (Request.IsAjaxRequest()) return PartialView("_ListPost", barPosts); ViewData["barThread"] = barThread; return View(barPosts); }
/// <summary> /// 创建评论 /// </summary> /// <param name="comment">待创建评论</param> /// <returns>创建成功返回true,否则返回false</returns> public bool Create(Comment comment) { //触发事件 EventBus<Comment>.Instance().OnBefore(comment, new CommonEventArgs(EventOperationType.Instance().Create())); AuditService auditService = new AuditService(); auditService.ChangeAuditStatusForCreate(comment.UserId, comment); //评论创建 long commentId = Convert.ToInt64(commentRepository.Insert(comment)); //更新父级ChildCount if (commentId > 0) { ICommentBodyProcessor commentBodyProcessor = DIContainer.Resolve<ICommentBodyProcessor>(); comment.Body = commentBodyProcessor.Process(comment.Body, TenantTypeIds.Instance().Comment(), commentId, comment.UserId); commentRepository.Update(comment); commentRepository.UpdateChildCount(comment.ParentId, false); CountService countService = new CountService(comment.TenantTypeId); countService.ChangeCount(CountTypes.Instance().CommentCount(), comment.CommentedObjectId, comment.OwnerId, 1, true); //触发事件 EventBus<Comment>.Instance().OnAfter(comment, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus<Comment, AuditEventArgs>.Instance().OnAfter(comment, new AuditEventArgs(null, comment.AuditStatus)); } return commentId > 0; }
/// <summary> /// 文章详细页 /// </summary> public ActionResult Detail(string spaceKey, long threadId) { BlogThread blogThread = blogService.Get(threadId); if (blogThread == null) { return HttpNotFound(); } if (!authorizer.BlogThread_View(blogThread)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "由于空间主人的权限设置,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint })); } long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (!authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId) && blogThread.UserId != currentSpaceUserId && (int)blogThread.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(BlogConfig.Instance().ApplicationId))) return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "尚未通过审核", Body = "由于当前文章尚未通过审核,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint })); //附件信息 IEnumerable<Attachment> attachments = attachmentService.GetsByAssociateId(threadId); if (attachments != null && attachments.Count() > 0) { ViewData["attachments"] = attachments.Where(n => n.MediaType == MediaType.Other); } //更新浏览计数 CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().HitTimes(), blogThread.ThreadId, blogThread.UserId, 1, false); //设置SEO信息 pageResourceManager.InsertTitlePart(blogThread.Author); pageResourceManager.InsertTitlePart(blogThread.ResolvedSubject); List<string> keywords = new List<string>(); keywords.AddRange(blogThread.TagNames); keywords.AddRange(blogThread.OwnerCategoryNames); string keyword = string.Join(" ", keywords.Distinct()); if (!string.IsNullOrEmpty(blogThread.Keywords)) { keyword += " " + blogThread.Keywords; } pageResourceManager.SetMetaOfKeywords(keyword); if (!string.IsNullOrEmpty(blogThread.Summary)) { pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(blogThread.Summary, true, false)); } ViewData["User"] = blogThread.User; return View(blogThread); }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册计数服务 CountService countService = new CountService(TenantTypeIds.Instance().ContentItem()); countService.RegisterCounts(); countService.RegisterCountPerDay(); countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 7); countService.RegisterStageCount(CountTypes.Instance().CommentCount(), 7); countService = new CountService(TenantTypeIds.Instance().ContentAttachment()); countService.RegisterCounts(); //注册用户计数服务(用于内容计数) OwnerDataSettings.RegisterStatisticsDataKeys(TenantTypeIds.Instance().User(), OwnerDataKeys.Instance().ContributeCount()); //注册标签云标签链接接口实现 TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().ContentItem(), new CmsTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(applicationId, new List<string> { "CMSAdministrator" }); }