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="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); }
/// <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); }
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(); }
//关于缓存期限: //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> public void GenerateByRole(long userId, string pointItemKey, string description) { //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); }
/// <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="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="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="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; }
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="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="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="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="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> /// <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> /// <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; }
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> /// <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 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> 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> /// <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; }