/// <summary> /// 删除垃圾数据 /// </summary> /// <param name="serviceKey">服务标识</param> public void DeleteTrashDatas() { IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Attitude()); List <Sql> sqls = new List <Sql>(); sqls.Add(Sql.Builder.Append("delete from tn_AttitudeRecords where not exists (select 1 from tn_Users where UserId = tn_AttitudeRecords.UserId)")); foreach (var tenantType in tenantTypes) { Type type = Type.GetType(tenantType.ClassType); if (type == null) { continue; } var pd = TableInfo.FromPoco(type); sqls.Add(Sql.Builder.Append("delete from tn_Attitudes") .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); sqls.Add(Sql.Builder.Append("delete from tn_AttitudeRecords") .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); } CreateDAO().Execute(sqls); }
public ActionResult _CreateBarPost(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) return Content(string.Empty); BarPost post = barPostService.Get(activity.SourceId); if (post == null) return Content(string.Empty); BarThread thread = barThreadService.Get(activity.ReferenceId); if (thread == null) return Content(string.Empty); ViewData["BarThread"] = thread; ViewData["Attachments"] = thread.Attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault(); ViewData["ActivityId"] = ActivityId; if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar()) { var tenantType = new TenantTypeService().Get(thread.BarSection.TenantTypeId); string tenantTypeName = string.Empty; if (tenantType != null) tenantTypeName = tenantType.Name; ViewData["tenantTypeName"] = tenantTypeName; } return View(post); }
/// <summary> /// 删除垃圾数据 /// </summary> /// <param name="serviceKey">服务标识</param> public void DeleteTrashDatas() { IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Attachment()); List <Sql> sqls = new List <Sql>(); sqls.Add(Sql.Builder.Append("delete from tn_AttachmentDownloadRecords where not exists (select 1 from tn_Users where UserId = tn_AttachmentDownloadRecords.UserId)")); sqls.Add(Sql.Builder.Append("update tn_Attachments set AssociateId = 0,UserId = 0,OwnerId = 0") .Where("not exists (select 1 from tn_Users where tn_Attachments.UserId = UserId)")); foreach (var tenantType in tenantTypes) { Type type = Type.GetType(tenantType.ClassType); if (type == null) { continue; } var pd = PetaPoco.Database.PocoData.ForType(type); sqls.Add(Sql.Builder.Append("update tn_Attachments set AssociateId = 0,UserId = 0,OwnerId = 0") .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where tn_Attachments.AssociateId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); sqls.Add(Sql.Builder.Append("delete from tn_AttachmentDownloadRecords") .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where AssociateId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0" , tenantType.TenantTypeId)); } CreateDAO().Execute(sqls); }
/// <summary> /// 删除垃圾数据 /// </summary> public void DeleteTrashCount() { TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable <TenantType> tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Count()); List <Sql> sqls = new List <Sql>(); foreach (var tenantType in tenantTypes) { Type type = Type.GetType(tenantType.ClassType); if (type == null) { continue; } var pd = TableInfo.FromPoco(type); sqls.Add(Sql.Builder.Append("delete from " + GetTableName_Counts(tenantType.TenantTypeId)) .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ")")); } CreateDAO().Execute(sqls); }
/// <summary> /// 资讯操作日志事件处理 /// </summary> private void RecommendOperationLogEventModule_After(RecommendItem sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create() || eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { TenantTypeService tenantTypeService = new TenantTypeService(); TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId); if (tenantType == null) return; OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = tenantType.ApplicationId; entry.Source = tenantType.Name; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = sender.ItemName; entry.OperationObjectId = sender.ItemId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), tenantType.Name + "推荐", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
public ActionResult ManageRecommendUsers(string tenantTypeId = null, string recommendTypeId = null, int pageSize = 20, int pageIndex = 1) { pageResourceManager.InsertTitlePart("推荐用户管理"); TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable<TenantType> tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Recommend()); ViewData["tenantList"] = new SelectList(tenantTypes, "TenantTypeId", "Name", tenantTypeId); IEnumerable<RecommendItemType> recommendItemTypes = recommendService.GetRecommendTypes(tenantTypeId).Where(n => n.TenantTypeId == TenantTypeIds.Instance().User()); ViewData["typeList"] = new SelectList(recommendItemTypes, "TypeId", "Name", recommendTypeId); PagingDataSet<RecommendItem> pds = recommendService.GetsForAdmin(TenantTypeIds.Instance().User(), recommendTypeId, null, pageSize, pageIndex); return View(pds); }
public ActionResult ManageRecommendItems(string tenantTypeId = null, string recommendTypeId = null, bool? isLink = null, int pageSize = 20, int pageIndex = 1) { pageResourceManager.InsertTitlePart("推荐内容管理"); TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable<TenantType> tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Recommend()).Where(n => n.TenantTypeId != TenantTypeIds.Instance().User()); ViewData["tenantList"] = new SelectList(tenantTypes, "TenantTypeId", "Name", tenantTypeId); IEnumerable<RecommendItemType> recommendItemTypes = recommendService.GetRecommendTypes(tenantTypeId).Where(n => n.TenantTypeId != TenantTypeIds.Instance().User()); ViewData["typeList"] = new SelectList(recommendItemTypes, "TypeId", "Name", recommendTypeId); List<SelectListItem> items = new List<SelectListItem> { new SelectListItem { Text = "是", Value = true.ToString() }, new SelectListItem { Text = "否", Value = false.ToString() } }; ViewData["isLink"] = new SelectList(items, "Value", "Text", isLink); PagingDataSet<RecommendItem> pds = recommendService.GetsForAdmin(tenantTypeId, recommendTypeId, isLink, pageSize, pageIndex); return View(pds); }
/// <summary> /// 所属下拉框绑定 /// </summary> /// <param name="tenantTypeId"></param> /// <returns></returns> private SelectList GetTenantSelectList(string tenantTypeId) { TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable<TenantType> tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Recommend()); SelectList tenants = new SelectList(tenantTypes, "TenantTypeId", "Name", tenantTypeId); return tenants; }
/// <summary> /// 是否具有创建BarThread的权限 /// </summary> /// <param name="authorizer"></param> /// <param name="sectionId">所属帖吧Id</param> /// <param name="errorMessage">无权信息提示</param> /// <returns></returns> public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage) { errorMessage = string.Empty; IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { errorMessage = "您需要先登录,才能发帖"; return false; } BarSectionService barSectionService = new BarSectionService(); var barSection = barSectionService.Get(sectionId); if (barSection == null) { errorMessage = "贴吧不存在"; return false; } if (authorizer.BarSection_Manage(barSection)) return true; if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread())) { if (currentUser.IsModerated) errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied; return false; } if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar()) { ISettingsManager<BarSettings> barSettingsManager = DIContainer.Resolve<ISettingsManager<BarSettings>>(); BarSettings barSetting = barSettingsManager.Get(); if (barSetting.OnlyFollowerCreateThread) { SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); if (subscribeService.IsSubscribed(sectionId, currentUser.UserId)) return true; else { errorMessage = "您需要先关注此帖吧,才能发帖"; return false; } } else return true; } else { if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId)) return true; else { TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId); errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name); return false; } } }
/// <summary> /// 是否具有管理BarSection的权限 /// </summary> /// <param name="barSection"></param> /// <returns></returns> public static bool BarSection_Manage(this Authorizer authorizer, BarSection barSection) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return false; if (barSection == null) return false; if (barSection.AuditStatus == AuditStatus.Success) { //吧主 if (barSection.UserId == currentUser.UserId) return true; //吧管理员 if (authorizer.AuthorizationService.IsTenantManager(currentUser, barSection.TenantTypeId, barSection.SectionId)) return true; } TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId); int applicationId = BarConfig.Instance().ApplicationId; if (tenantType != null) applicationId = tenantType.ApplicationId; if (authorizer.IsAdministrator(applicationId)) return true; return false; }
public ActionResult _RecommendItem(string tenantTypeId, long itemId = 0, string itemName = null, string recommendItemTypeId = null, bool showLink = false, long recommendId = 0, bool showInList = true, long userId = 0) { RecommendItem recommendItem = null; if (recommendId > 0) { recommendItem = recommendService.Get(recommendId); if (recommendItem == null) return HttpNotFound(); tenantTypeId = recommendItem.TenantTypeId; itemId = recommendItem.ItemId; recommendItemTypeId = recommendItem.TypeId; ViewData["RecommendTypeName"] = recommendItem.RecommendItemType.Name; ViewData["RecommendTypeId"] = recommendItem.TypeId; } if (!authorizer.RecommendItem_Manage(tenantTypeId)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有管理推荐内容的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint })); } IEnumerable<RecommendItemType> itemTypes = recommendService.GetRecommendTypes(tenantTypeId); IEnumerable<RecommendItem> recommendItems = recommendService.Gets(itemId, tenantTypeId); //已修改 RecommendItemEditModel itemEditModel = new RecommendItemEditModel(); ViewData["recommendItems"] = recommendItems; //已修改 ViewData["TypeId"] = new SelectList(itemTypes, "TypeId", "Name", recommendItemTypeId); if (recommendId != 0) { itemEditModel = recommendItem.AsEditModel(); ViewData["HasFeaturedImage"] = recommendItem.RecommendItemType.HasFeaturedImage; } else { if (itemTypes != null && itemTypes.Count() > 0 && string.IsNullOrEmpty(recommendItemTypeId)) { //已修改 recommendItemTypeId = itemTypes.First().TypeId; } if (!string.IsNullOrEmpty(recommendItemTypeId)) { recommendItem = recommendService.Get(itemId, recommendItemTypeId); RecommendItemType recommendType = recommendService.GetRecommendType(recommendItemTypeId); ViewData["HasFeaturedImage"] = recommendType.HasFeaturedImage; ViewData["RecommendTypeName"] = recommendType.Name; ViewData["RecommendTypeId"] = recommendType.TypeId; if (recommendItem != null && !recommendItem.IsLink) { ViewData["ExpiredDate"] = recommendItem.ExpiredDate; itemEditModel = recommendItem.AsEditModel(); } else { RecommendItem newItem = RecommendItem.New(); newItem.ItemName = itemName; newItem.ItemId = itemId; newItem.TenantTypeId = tenantTypeId; newItem.ExpiredDate = DateTime.UtcNow.AddMonths(1); newItem.UserId = userId; itemEditModel = newItem.AsEditModel(); } } else { StatusMessageData message = null; TenantTypeService tenantTypeService = new TenantTypeService(); TenantType tenantType = tenantTypeService.Get(tenantTypeId); if (tenantType == null) { message = new StatusMessageData(StatusMessageType.Hint, "没有推荐类别"); } else { message = new StatusMessageData(StatusMessageType.Hint, tenantType.Name + "下没有推荐类别"); } ViewData["statusMessageData"] = message; } } ViewData["showLink"] = showLink || itemEditModel.IsLink; ViewData["showInList"] = showInList; return View(itemEditModel); }
public ActionResult ManageThreads(string spaceKey, ManageThreadEditModel model, int pageIndex = 1) { long groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); BarSection section = barSectionService.Get(groupId); if (!authorizer.BarSection_Manage(section)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = string.Format("��û��Ȩ���� {0} ��", section == null ? "" : section.Name), Title = "û��Ȩ��", StatusMessageType = StatusMessageType.Hint })); } var group = groupService.Get(spaceKey); pageResourceManager.InsertTitlePart(group.GroupName); pageResourceManager.InsertTitlePart("���ɹ���"); List<SelectListItem> SelectListItem_TrueAndFlase = new List<SelectListItem> { new SelectListItem { Text = "��", Value = true.ToString() }, new SelectListItem { Text = "��", Value = false.ToString() } }; ViewData["IsEssential"] = new SelectList(SelectListItem_TrueAndFlase, "Value", "Text", model.IsEssential); ViewData["IsSticky"] = new SelectList(SelectListItem_TrueAndFlase, "Value", "Text", model.IsSticky); IEnumerable<Category> categories = categoryService.GetOwnerCategories(section.SectionId, TenantTypeIds.Instance().BarThread()); ViewData["CategoryId"] = new SelectList(categories.Select(n => new { text = StringUtility.Trim(n.CategoryName, 20), value = n.CategoryId }), "value", "text", model.CategoryId); BarThreadQuery query = model.GetBarThreadQuery(); query.SectionId = section.SectionId; ViewData["BarThreads"] = barThreadService.Gets(TenantTypeIds.Instance().Group(), query, model.PageSize ?? 20, pageIndex); model.SectionId = section.SectionId; ViewData["TenantType"] = new TenantTypeService().Get(TenantTypeIds.Instance().Group()); return View(model); }
/// <summary> /// 推荐积分处理 /// </summary> /// <param name="sender">推荐实体</param> /// <param name="eventArgs">事件参数</param> void RecommendPointModule_After(RecommendItem sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().Create()) { return; } string pointItemKey = string.Empty; PointService pointService = new PointService(); string description = string.Empty; TenantTypeService tenantTypeService = new TenantTypeService(); var urlGetter = RecommendUrlGetterFactory.Get(sender.TenantTypeId); NoticeService noticeService = new NoticeService(); Notice notice = Notice.New(); notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.TemplateName = "FollowUser"; notice.UserId = sender.UserId; notice.LeadingActorUserId = sender.ReferrerId; notice.LeadingActor = sender.ReferrerName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.ReferrerId)); notice.RelativeObjectId = sender.UserId; notice.RelativeObjectName = sender.ItemName; notice.RelativeObjectUrl = sender.DetailUrl; if (sender.TenantTypeId == TenantTypeIds.Instance().User()) { pointItemKey = PointItemKeys.Instance().RecommendUser(); description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendUser")); notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommendedUser(); } else { pointItemKey = PointItemKeys.Instance().RecommendContent(); TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId); if (tenantType == null) return; description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendContent"), tenantType.Name, sender.ItemName); notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommended(); } noticeService.Create(notice); pointService.GenerateByRole(sender.UserId, pointItemKey, description); }
public ActionResult _CreateBarRating(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) return HttpNotFound(); BarRating rating = barRatingService.Get(activity.SourceId); if (rating == null) return HttpNotFound(); ViewData["BarRating"] = rating; BarThread thread = barThreadService.Get(activity.ReferenceId); if (thread == null) return HttpNotFound(); ViewData["ActivityId"] = ActivityId; //todo:bianchx,by zhengw:相同问题,做个记号 ViewData["Attachments"] = thread.Attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault(); if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar()) { var tenantType = new TenantTypeService().Get(thread.BarSection.TenantTypeId); string tenantTypeName = string.Empty; if (tenantType != null) tenantTypeName = tenantType.Name; ViewData["tenantTypeName"] = tenantTypeName; } return View(thread); }
/// <summary> /// 重建缩略图 /// </summary> /// <returns></returns> public ActionResult RebuildingThumbnails() { IEnumerable<TenantAttachmentSettings> tenantAttachmentSettings = TenantAttachmentSettings.GetAll(); ViewData["TenantAttachmentSettings"] = tenantAttachmentSettings; ViewData["TenantLogoSettings"] = TenantLogoSettings.GetAll(); IStoreProvider storeProvider = DIContainer.Resolve<IStoreProvider>(); string rootPath = WebUtility.GetPhysicalFilePath("~"); string uploadsPath = storeProvider.StoreRootPath; if (storeProvider.StoreRootPath.StartsWith(rootPath)) uploadsPath = uploadsPath.Replace(rootPath, ""); ViewData["uploadsPath"] = uploadsPath; Dictionary<string, string> ApplicationName = new Dictionary<string, string>(); TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable<TenantType> tenantTypes = tenantTypeService.Gets(null, null); foreach (var item in tenantTypes) { TenantType type = tenantTypeService.Get(item.TenantTypeId); ApplicationName[item.TenantTypeId] = type != null ? type.Name : item.Name; } ViewData["ApplicationName"] = ApplicationName; return View(); }
/// <summary> /// 帖吧选择器显示的页面 /// </summary> /// <param name="categoryId">分类id</param> /// <param name="selectedSectionId">默认被选中的帖吧</param> /// <returns>帖吧选择器</returns> public ActionResult _BarSetionSelectItem(string name, long? categoryId = null, long? selectedSectionId = null, bool isHidden = false, string tenantTypeId = null) { tenantTypeId = (string.IsNullOrEmpty(tenantTypeId) || tenantTypeId.Equals(TenantTypeIds.Instance().Bar())) ? TenantTypeIds.Instance().BarSection() : tenantTypeId; ViewData["IsHidden"] = isHidden; ViewData["TenantTypeId"] = tenantTypeId; ViewData["Name"] = name; IEnumerable<Category> childCategories = null; ViewData["CategoryId"] = categoryId; string tenantTypeName = "帖吧"; var tenantType = new TenantTypeService().Get(tenantTypeId); if (tenantType != null) tenantTypeName = tenantType.Name; ViewData["TenantTypeName"] = tenantTypeName; if (categoryId.HasValue) { Category category = categoryService.Get(categoryId ?? 0); if (category != null) { if (category.ChildCount > 0) childCategories = category.Children; else if (category.Parent != null) childCategories = category.Parent.Children; } List<Category> allParentCategories = new List<Category>(); GetAllParentCategories(category, ref allParentCategories); ViewData["AllParentCategories"] = allParentCategories; } if (childCategories == null) childCategories = categoryService.GetRootCategories(tenantTypeId); if (categoryId.HasValue) { List<Category> categories = childCategories.ToList(); Category category = categories.Where(n => n.CategoryId == (categoryId ?? 0)).FirstOrDefault(); if (category != null) { categories.Remove(category); categories.Insert(0, category); childCategories = categories; } } ViewData["ChildCategories"] = childCategories; //ViewData["BarSections"] = barSectionService.GetTops(200, categoryId, SortBy_BarSection.FollowedCount); if (string.IsNullOrEmpty(tenantTypeId) || tenantTypeId == TenantTypeIds.Instance().BarSection()) { tenantTypeId = TenantTypeIds.Instance().Bar(); } ViewData["BarSections"] = barSectionService.Gets(tenantTypeId, new BarSectionQuery { CategoryId = categoryId }, 200, 1); BarSection section = null; if (selectedSectionId.HasValue) section = barSectionService.Get(selectedSectionId ?? 0); return View(section); }
public ActionResult _CreateBarThread(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) return Content(string.Empty); BarThread thread = barThreadService.Get(activity.SourceId); if (thread == null) return Content(string.Empty); PagingDataSet<BarPost> barPosts = barPostService.Gets(thread.ThreadId, false, SortBy_BarPost.DateCreated_Desc); ViewData["BarPosts"] = barPosts.Take(3); IEnumerable<Attachment> attachments = attachementService.GetsByAssociateId(thread.ThreadId); if (attachments != null && attachments.Count() > 0) { IEnumerable<Attachment> attachmentImages = attachments.Where(n => n.MediaType == MediaType.Image); if (attachmentImages != null && attachmentImages.Count() > 0) ViewData["Attachments"] = attachmentImages; } ViewData["ActivityId"] = ActivityId; if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar()) { var tenantType = new TenantTypeService().Get(thread.BarSection.TenantTypeId); string tenantTypeName = string.Empty; if (tenantType != null) tenantTypeName = tenantType.Name; ViewData["tenantTypeName"] = tenantTypeName; } return View(thread); }