/// <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); }
/// <summary> /// 创建回复贴 /// </summary> /// <param name="post">回复贴</param> public bool Create(BarPost post) { BarSectionService barSectionService = new BarSectionService(); BarSection barSection = barSectionService.Get(post.SectionId); if (barSection == null) { return(false); } EventBus <BarPost> .Instance().OnBefore(post, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(post.UserId, post); long id = 0; long.TryParse(barPostRepository.Insert(post).ToString(), out id); if (id > 0) { new AttachmentService(TenantTypeIds.Instance().BarPost()).ToggleTemporaryAttachments(post.UserId, TenantTypeIds.Instance().BarPost(), id); //计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true); if (post.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数+1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(post.SectionId, OwnerDataKeys.Instance().PostCount(), 1); } else if (post.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(post.UserId, OwnerDataKeys.Instance().PostCount(), 1); } //更新帖子主题计数缓存 RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(BarThread)).RealTimeCacheHelper; string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(post.ThreadId); ICacheService cacheService = DIContainer.Resolve <ICacheService>(); BarThread barThread = cacheService.Get <BarThread>(cacheKey); if (barThread != null && barThread.ThreadId > 0) { barThread.PostCount++; cacheService.Set(cacheKey, barThread, CachingExpirationType.SingleObject); } new AtUserService(TenantTypeIds.Instance().BarPost()).ResolveBodyForEdit(post.GetBody(), post.UserId, post.PostId); EventBus <BarPost> .Instance().OnAfter(post, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BarPost, AuditEventArgs> .Instance().OnAfter(post, new AuditEventArgs(null, post.AuditStatus)); } return(id > 0); }
/// <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); }
/// <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())); }
/// <summary> /// 商品描述 /// </summary> /// <returns></returns> public ActionResult GiftDetail(long giftId) { ViewData["giftId"] = giftId; //获取商品 PointGift gift = pointMallService.GetGift(giftId); //更新计数 CountService countService = new CountService(TenantTypeIds.Instance().PointGift()); countService.ChangeCount(CountTypes.Instance().HitTimes(), giftId, gift.UserId, 1); pageResourceManager.InsertTitlePart(gift.Name); IUser currentUser = UserContext.CurrentUser; if (currentUser != null) { //设置最近浏览 HttpCookie cookie = Request.Cookies["LastViewedGifts" + currentUser.UserId]; if (cookie != null) { string[] cookieGiftIds = cookie.Value.ToString().Split(','); cookie.Value = ""; foreach (string cookieGiftId in cookieGiftIds) { if (!string.IsNullOrWhiteSpace(cookieGiftId)) { if (Convert.ToInt64(cookieGiftId) != giftId) { cookie.Value = cookie.Value + "," + cookieGiftId; } } } cookie.Value = giftId + "," + cookie.Value; Response.Cookies.Set(cookie); } else { cookie = new HttpCookie("LastViewedGifts" + currentUser.UserId); cookie.Value = giftId.ToString(); Response.Cookies.Add(cookie); } } //获取 ViewData["successCommentsCount"] = pointMallService.GetRecordsCount(giftId, ApproveStatus.Approved).TotalRecords; ViewData["pendingCommentsCount"] = pointMallService.GetRecordsCount(giftId, ApproveStatus.Pending).TotalRecords; return(View(gift)); }
/// <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)); }
/// <summary> /// 删除回复贴 /// </summary> /// <param name="postId">回复贴Id</param> public void Delete(long postId) { BarPost post = barPostRepository.Get(postId); if (post == null) { return; } BarSectionService barSectionService = new BarSectionService(); BarSection barSection = barSectionService.Get(post.SectionId); if (barSection == null) { return; } EventBus <BarPost> .Instance().OnBefore(post, new CommonEventArgs(EventOperationType.Instance().Delete())); int affectCount = barPostRepository.Delete(post); if (affectCount > 0) { //更新帖吧的计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1 - post.ChildPostCount, true); if (post.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数-1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(post.SectionId, OwnerDataKeys.Instance().PostCount(), -1); } else if (post.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(post.UserId, OwnerDataKeys.Instance().PostCount(), -1); } EventBus <BarPost> .Instance().OnAfter(post, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <BarPost, AuditEventArgs> .Instance().OnAfter(post, new AuditEventArgs(post.AuditStatus, null)); } }
/// <summary> /// 照片详细显示 /// </summary> /// <returns></returns> public ActionResult Detail(long photoId) { Photo photo = photoService.GetPhoto(photoId); //更新计数 CountService countService = new CountService(TenantTypeIds.Instance().Photo()); countService.ChangeCount(CountTypes.Instance().HitTimes(), photoId, photo.UserId, 1, true); Album album = photo.Album; if (photo == null || !authorizer.Album_View(album)) { if (Request.IsAjaxRequest()) { return(Json(new StatusMessageData(StatusMessageType.Hint, "没有浏览照片的权限"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有浏览照片的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint }))); } } IUser currentUser = UserContext.CurrentUser; PagingDataSet <Photo> photos = photoService.GetPhotosOfAlbum(null, photo.AlbumId, currentUser != null && currentUser.UserId == album.UserId, pageSize: 1000, pageIndex: 1); ViewData["album"] = album; ViewData["photos"] = photos.ToList(); if (Request.IsAjaxRequest()) { return(PartialView("_Details", photo)); } return(View(photo)); }
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 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> /// <returns></returns> public ActionResult PageDetail(long pageId, long?versionId = null) { SiteSettings siteSettings = siteSettingsManager.Get(); if (!siteSettings.EnableAnonymousBrowse) { //匿名用户访问 if (UserContext.CurrentUser == null) { string EncryptKey = System.Configuration.ConfigurationManager.AppSettings["EncryptKey"].ToString(); if (EncryptKey != "false") { string anonymous = Request.QueryString.Get("anonymous"); if (string.IsNullOrEmpty(anonymous)) { return(Redirect(SiteUrls.Instance().Login(true))); } } } } WikiPage currentPage = wikiService.Get(pageId); //待审核的词条只有作者和管理员查看 if (currentPage.AuditStatus != AuditStatus.Success) { if (UserContext.CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } else if (!DIContainer.Resolve <Authorizer>().Page_Manage(currentPage) && UserContext.CurrentUser.UserId != currentPage.UserId) { return(Redirect(SiteUrls.Instance().Index())); } } //判断输入参数的有效性 if (currentPage == null) { return(HttpNotFound()); } if (versionId.HasValue && versionId.Value > 0) { //设置标题 pageResourceManager.InsertTitlePart("查看词条历史版本"); ViewData["LastestVersion"] = wikiService.GetPageVersion(versionId.Value); } else { //设置标题 pageResourceManager.InsertTitlePart("词条详细页"); //浏览量 CountService countService = new CountService(TenantTypeIds.Instance().WikiPage()); countService.ChangeCount(CountTypes.Instance().HitTimes(), pageId, currentPage.UserId, 1, false); //获取数据在View展示 //A 词条当前版本 ViewData["LastestVersion"] = currentPage.LastestVersion; } //B 分类-最新版本的属性中有 //C 标签-最新版本的属性中有 //D 附件 IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(pageId); if (attachments != null && attachments.Count() > 0) { ViewData["attachmentCount"] = attachments.Where(n => n.MediaType == MediaType.Other).Count(); } IEnumerable <WikiPage> hotPages = wikiService.GetTops(TenantTypeIds.Instance().Wiki(), 10, null, null, SortBy_WikiPage.StageHitTimes); ViewData["hotPages"] = hotPages; //增加计数 CountService usercountService = new CountService(TenantTypeIds.Instance().User()); return(View(currentPage)); }
/// <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)); } return(View(blogThread)); }
/// <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> /// <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="blogThread">日志实体</param> public bool Create(BlogThread blogThread, string privacyStatus1 = null, string privacyStatus2 = null) { //设计要点 //1、使用AuditService设置审核状态; //2、注意调用AttachmentService转换临时附件; //3、需要触发的事件参见《设计说明书-日志》 //4、草稿的审核状态为待审核; //5、转载的日志还需要为原日志转载数+1(调用计数服务); EventBus <BlogThread> .Instance().OnBefore(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态,草稿的审核状态为待审核 if (blogThread.IsDraft) { blogThread.AuditStatus = AuditStatus.Pending; } else { AuditService auditService = new AuditService(); auditService.ChangeAuditStatusForCreate(blogThread.UserId, blogThread); } long threadId = 0; long.TryParse(blogThreadRepository.Insert(blogThread).ToString(), out threadId); if (threadId > 0) { //转换临时附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BlogThread()); attachmentService.ToggleTemporaryAttachments(blogThread.OwnerId, TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); //原日志转载数+1 if (blogThread.IsReproduced) { CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().ReproduceCount(), blogThread.OriginalThreadId, blogThread.OwnerId, 1, true); } //用户内容计数+1 if (!blogThread.IsDraft) { OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(blogThread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BlogThread()); atUserService.ResolveBodyForEdit(blogThread.GetBody(), blogThread.UserId, blogThread.ThreadId); //设置隐私状态 UpdatePrivacySettings(blogThread, privacyStatus1, privacyStatus2); EventBus <BlogThread> .Instance().OnAfter(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BlogThread, AuditEventArgs> .Instance().OnAfter(blogThread, new AuditEventArgs(null, blogThread.AuditStatus)); return(true); } return(false); }
/// <summary> /// 回答被赞同的相关事件处理 /// </summary> private void AskAnswerSupportEventModule_After(long objectId, SupportOpposeEventArgs eventArgs) { if (eventArgs.TenantTypeId == TenantTypeIds.Instance().AskAnswer()) { //如果不是第一次顶踩,则不处理 if (!eventArgs.FirstTime) { return; } if (eventArgs.EventOperationType == EventOperationType.Instance().Support()) { AskAnswer answer = askService.GetAnswer(objectId); AskQuestion question = answer.Question; //创建顶回答的动态[关注回答者的粉丝可以看到该顶信息] Activity activityOfFollower = Activity.New(); activityOfFollower.ActivityItemKey = ActivityItemKeys.Instance().SupportAskAnswer(); activityOfFollower.ApplicationId = AskConfig.Instance().ApplicationId; activityOfFollower.IsOriginalThread = true; activityOfFollower.IsPrivate = false; activityOfFollower.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.SourceId = answer.AnswerId; activityOfFollower.UserId = eventArgs.UserId; activityOfFollower.ReferenceId = answer.AnswerId; activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfFollower.OwnerId = eventArgs.UserId; activityOfFollower.OwnerName = userService.GetFullUser(eventArgs.UserId).DisplayName; activityOfFollower.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activityOfFollower, true); //创建顶回答的动态[关注该问题的用户可以看到该顶信息] Activity activityOfQuestionSubscriber = Activity.New(); activityOfQuestionSubscriber.ActivityItemKey = ActivityItemKeys.Instance().SupportAskAnswer(); activityOfQuestionSubscriber.ApplicationId = AskConfig.Instance().ApplicationId; activityOfQuestionSubscriber.IsOriginalThread = true; activityOfQuestionSubscriber.IsPrivate = false; activityOfQuestionSubscriber.TenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.SourceId = answer.AnswerId; activityOfQuestionSubscriber.UserId = eventArgs.UserId; activityOfQuestionSubscriber.ReferenceId = answer.AnswerId; activityOfQuestionSubscriber.ReferenceTenantTypeId = TenantTypeIds.Instance().AskAnswer(); activityOfQuestionSubscriber.OwnerId = question.QuestionId; activityOfQuestionSubscriber.OwnerName = question.Subject; activityOfQuestionSubscriber.OwnerType = ActivityOwnerTypes.Instance().AskQuestion(); activityService.Generate(activityOfQuestionSubscriber, false); //处理积分和威望 string pointItemKey = PointItemKeys.Instance().Ask_BeSupported(); //回答收到赞同时产生积分 string eventOperationType = EventOperationType.Instance().Support(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey, description); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); //赞同者自动关注问题 if (!subscribeService.IsSubscribed(question.QuestionId, eventArgs.UserId)) { subscribeService.Subscribe(question.QuestionId, eventArgs.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } //增加赞同的用户计数 ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerSupportCount(), 1); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Oppose()) { AskAnswer answer = askService.GetAnswer(objectId); AskQuestion question = answer.Question; //处理积分和威望 string pointItemKey = PointItemKeys.Instance().Ask_BeOpposed(); //回答收到反对时产生积分 string eventOperationType = EventOperationType.Instance().Oppose(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "回答", question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey, description); //记录用户的威望 PointItem pointItem = pointService.GetPointItem(pointItemKey); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem.ReputationPoints); //反对者自动关注问题 if (!subscribeService.IsSubscribed(question.QuestionId, eventArgs.UserId)) { subscribeService.Subscribe(answer.QuestionId, eventArgs.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } //增加反对的用户计数 ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerOpposeCount(), 1); } } }
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(); }