Beispiel #1
0
        /// <summary>
        /// 内容处理
        /// </summary>
        /// <param name="body">待处理内容</param>
        /// <param name="associateId">待处理相关项Id</param>
        /// <param name="userId">相关项作者</param>
        /// <param name="ownerId">拥有者Id</param>
        /// <returns></returns>
        public string Process(string body, string ownerTenantTypeId, long associateId, long userId, long ownerId)
        {
            string        tenantTypeId  = TenantTypeIds.Instance().Microblog();
            AtUserService atUserService = new AtUserService(tenantTypeId);

            body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate);

            TagService tagService = new TagService(tenantTypeId);

            Func <KeyValuePair <string, long>, long, string> topicTagGenerate = delegate(KeyValuePair <string, long> _tagNameWithId, long _ownerId)
            {
                return(string.Format("<a href=\"{1}\">#{0}#</a>", _tagNameWithId.Key, MicroblogUrlGetterFactory.Get(ownerTenantTypeId).TopicDetail(_tagNameWithId.Key.Trim(), _ownerId)));
            };

            body = tagService.ResolveBodyForDetail(body, associateId, ownerId, topicTagGenerate);

            body = body.Replace("\n", "<br/>");

            EmotionService emotionService = DIContainer.Resolve <EmotionService>();

            body = emotionService.EmoticonTransforms(body);

            ParsedMediaService parsedMediaService = DIContainer.Resolve <ParsedMediaService>();

            body = parsedMediaService.ResolveBodyForDetail(body, associateId, userId, UrlTagGenerate);

            return(body);
        }
        public JsonResult _SetCategory(string threadIds, long categoryId)
        {
            CategoryService categoryService = new CategoryService();
            IUser           currentUser     = UserContext.CurrentUser;


            if (!string.IsNullOrEmpty(threadIds))
            {
                var ids = threadIds.TrimEnd(',').Split(',');
                foreach (var id in ids)
                {
                    categoryService.ClearCategoriesFromItem(long.Parse(id), 0, TenantTypeIds.Instance().BlogThread());
                    categoryService.AddCategoriesToItem(new List <long>()
                    {
                        categoryId
                    }, long.Parse(id));
                }

                return(Json(new StatusMessageData(StatusMessageType.Success, "设置分类成功!")));
            }
            else
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "请选择要设置的日志!")));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 我的文章/Ta的文章
        /// </summary>
        public ActionResult Blog(string spaceKey, int pageIndex = 1)
        {
            PagingDataSet <BlogThread> blogs = null;

            IUser currentUser = UserContext.CurrentUser;

            if (currentUser != null && currentUser.UserName == spaceKey)
            {
                blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), currentUser.UserId, true, false, null, null, true, 20, pageIndex);

                pageResourceManager.InsertTitlePart("我的文章");
                return(View("My", blogs));
            }
            else
            {
                User user = userService.GetFullUser(spaceKey);
                if (user == null)
                {
                    return(HttpNotFound());
                }

                blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), user.UserId, false, true, null, null, true, 20, pageIndex);

                pageResourceManager.InsertTitlePart(user.DisplayName + "的文章");
                return(View("Ta", blogs));
            }
        }
Beispiel #4
0
        /// <summary>
        /// 更新ContentItem
        /// </summary>
        /// <param name="contentItem"></param>
        public void Update(ContentItem contentItem)
        {
            //执行事件
            EventBus <ContentItem> .Instance().OnBefore(contentItem, new CommonEventArgs(EventOperationType.Instance().Update()));

            AuditStatus prevAuditStatus = contentItem.AuditStatus;

            //设置审核状态
            AuditService auditService = new AuditService();

            auditService.ChangeAuditStatusForUpdate(contentItem.UserId, contentItem);
            if (contentItem.AdditionalProperties.Get <bool>("FirstAsTitleImage", false))
            {
                IEnumerable <Attachment> attachments = new AttachmentService(TenantTypeIds.Instance().ContentItem()).GetsByAssociateId(contentItem.ContentItemId);
                Attachment fristImage = attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault();
                if (fristImage != null)
                {
                    contentItem.FeaturedImageAttachmentId = fristImage.AttachmentId;
                    contentItem.FeaturedImage             = fristImage.GetRelativePath() + "\\" + fristImage.FileName;
                }
            }
            contentItemRepository.Update(contentItem);

            //执行事件
            EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Update(), ApplicationIds.Instance().CMS()));

            EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(prevAuditStatus, contentItem.AuditStatus));
        }
Beispiel #5
0
        /// <summary>
        /// 关注用户/取消关注动态处理
        /// </summary>
        /// <param name="sender">关注实体</param>
        /// <param name="eventArgs">事件参数</param>
        void FollowActivityEventModule_After(FollowEntity sender, CommonEventArgs eventArgs)
        {
            ActivityService activityService = new ActivityService();

            if (EventOperationType.Instance().Create() == eventArgs.EventOperationType)
            {
                IUser user = DIContainer.Resolve <UserService>().GetUser(sender.UserId);
                if (user == null)
                {
                    return;
                }

                Activity activity = Activity.New();

                activity.ActivityItemKey = ActivityItemKeys.Instance().FollowUser();
                activity.OwnerType       = ActivityOwnerTypes.Instance().User();
                activity.OwnerId         = sender.UserId;
                activity.OwnerName       = user.DisplayName;
                activity.UserId          = sender.UserId;
                activity.ReferenceId     = sender.FollowedUserId;
                activity.TenantTypeId    = TenantTypeIds.Instance().User();

                activityService.Generate(activity, false);

                activityService.TraceBackInboxAboutOwner(sender.UserId, sender.FollowedUserId, ActivityOwnerTypes.Instance().User());
            }
            else if (EventOperationType.Instance().Delete() == eventArgs.EventOperationType)
            {
                activityService.RemoveInboxAboutOwner(sender.UserId, sender.FollowedUserId, ActivityOwnerTypes.Instance().User());
            }
        }
Beispiel #6
0
        /// <summary>
        /// 编辑问题
        /// </summary>
        /// <remarks>
        /// 1.使用AuditService.ChangeAuditStatusForUpdate设置审核状态;
        /// 2.Repository更新时不处理:IsEssential
        /// 3.需要触发的事件:Update的OnBefore、OnAfter;
        /// </remarks>
        /// <param name="question">问题实体</param>
        /// <param name="changeAuditStatusForUpdate">是否更新审核状态</param>
        public void UpdateQuestion(AskQuestion question, bool changeAuditStatusForUpdate = true)
        {
            AskQuestion question_beforeUpDate = GetQuestion(question.QuestionId);

            if (question.Reward != question_beforeUpDate.Reward && question.Reward < (question.User.TradePoints + question_beforeUpDate.Reward))
            {
                question.AddedReward = question.Reward - question_beforeUpDate.Reward;
            }
            else
            {
                question.AddedReward = 0;
            }

            EventBus <AskQuestion> .Instance().OnBefore(question, new CommonEventArgs(EventOperationType.Instance().Update()));

            AuditStatus prevAuditStatus = question.AuditStatus;

            //设置审核状态
            if (changeAuditStatusForUpdate)
            {
                new AuditService().ChangeAuditStatusForUpdate(question.UserId, question);
            }

            askQuestionRepository.Update(question);

            AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().AskQuestion());

            atUserService.ResolveBodyForEdit(question.Body, question.UserId, question.QuestionId);

            EventBus <AskQuestion> .Instance().OnAfter(question, new CommonEventArgs(EventOperationType.Instance().Update()));

            EventBus <AskQuestion, AuditEventArgs> .Instance().OnAfter(question, new AuditEventArgs(prevAuditStatus, question.AuditStatus));
        }
Beispiel #7
0
        public string Process(string body, string tenantTypeId, long associateId, long userId)
        {
            //解析at用户
            AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().AskQuestion());

            body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate);

            AttachmentService        attachmentService = new AttachmentService(tenantTypeId);
            IEnumerable <Attachment> attachments       = attachmentService.GetsByAssociateId(associateId);

            if (attachments != null && attachments.Count() > 0)
            {
                IList <BBTag> bbTags       = new List <BBTag>();
                string        htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"javascript:;\" target=\"_blank\" menu=\"#attachement-artdialog-{4}\">{0}</a>(<em>{1}</em>{2},<em>下载次数:{3}</em>)</div>";

                //解析文本中附件
                IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image);
                foreach (var attachment in attachmentsFiles)
                {
                    bbTags.Add(AddBBTag(htmlTemplate, attachment));
                }

                body = HtmlUtility.BBCodeToHtml(body, bbTags);
            }

            return(body);
        }
Beispiel #8
0
        public ActionResult _HotComment(int topNum = 6)
        {
            IEnumerable <BlogThread> blogs = blogService.GetTops(TenantTypeIds.Instance().User(), topNum, null, null, SortBy_BlogThread.CommentCount);

            ViewData["blogs"] = blogs;
            return(View(blogs));
        }
Beispiel #9
0
        /// <summary>
        /// 日志频道首页
        /// </summary>
        public ActionResult Home(int pageIndex = 1)
        {
            PagingDataSet <BlogThread> blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.DateCreated_Desc, 15, pageIndex);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_List", blogs));
            }

            //获取推荐日志
            //图片推荐(幻灯片)
            IEnumerable <RecommendItem> recommendPicItems = recommendService.GetTops(5, blogSettings.RecommendPicTypeId);
            int linkCount      = recommendPicItems.Where(n => n.IsLink).Where(n => !string.IsNullOrEmpty(n.FeaturedImage)).Count();
            int blogCount      = blogService.GetBlogThreads(recommendPicItems.Where(n => !n.IsLink).Select(n => n.ItemId)).Where(n => !string.IsNullOrEmpty(n.FeaturedImage)).Count();
            int count          = recommendPicItems.Where(n => !n.IsLink).Where(n => !string.IsNullOrEmpty(n.FeaturedImage)).Count();
            int recommendCount = System.Math.Max(count, blogCount) + linkCount;

            ViewData["recommendPicBlogs"] = recommendPicItems;


            //文字推荐(幻灯片右侧文字区)
            IEnumerable <RecommendItem> recommendWordItems    = recommendService.GetTops(6, blogSettings.RecommendWordTypeId);
            IEnumerable <BlogThread>    recommendWordBlogsAll = blogService.GetBlogThreads(recommendWordItems.Where(n => !n.IsLink).Select(n => n.ItemId));

            ViewData["recommendCount"]     = recommendCount;
            ViewData["recommendWordItems"] = recommendWordItems;
            pageResourceManager.InsertTitlePart("日志首页");

            return(View(blogs));
        }
Beispiel #10
0
        /// <summary>
        /// 删除垃圾数据
        /// </summary>
        /// <param name="serviceKey">服务标识</param>
        public void DeleteTrashDatas()
        {
            IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Tag());
            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);

                if (tenantType.TenantTypeId == TenantTypeIds.Instance().User() || tenantType.TenantTypeId == TenantTypeIds.Instance().Group())
                {
                    sqls.Add(Sql.Builder.Append("delete from tn_TagsInOwners")
                             .Where("not exists (select 1 from " + pd.TableName + " where OwnerId = " + pd.PrimaryKey + ") and TenantTypeId = @0"
                                    , tenantType.TenantTypeId));
                }
                else
                {
                    sqls.Add(Sql.Builder.Append("delete from tn_ItemsInTags")
                             .Where("not exists (select 1 from " + pd.TableName + " where ItemId = " + pd.PrimaryKey + ") and TenantTypeId = @0"
                                    , tenantType.TenantTypeId));
                }
            }

            CreateDAO().Execute(sqls);
        }
Beispiel #11
0
        /// <summary>
        /// 日志排行页
        /// </summary>
        /// <param name="rank">区分最新日志,热门日志,热评日志,精华日志</param>
        //[DonutOutputCache(CacheProfile = "Stable")]
        public ActionResult ListByRank(string rank, int pageIndex = 1)
        {
            PagingDataSet <BlogThread> blogs = null;

            //最新日志
            if (rank == "new")
            {
                blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.DateCreated_Desc, 20, pageIndex);
                pageResourceManager.InsertTitlePart("最新日志");
            }
            //热门日志
            else if (rank == "hot")
            {
                blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.StageHitTimes, 20, pageIndex);
                pageResourceManager.InsertTitlePart("热门日志");
            }
            //热评日志
            else if (rank == "comment")
            {
                blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.CommentCount, 20, pageIndex);
                pageResourceManager.InsertTitlePart("热评日志");
            }
            //精华日志
            else
            {
                blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, true, SortBy_BlogThread.DateCreated_Desc, 20, pageIndex);
                pageResourceManager.InsertTitlePart("精华日志");
            }

            ViewData["rank"] = rank;
            return(View(blogs));
        }
Beispiel #12
0
        /// <summary>
        /// 获取匹配的前N条最热的搜索词(仅非人工干预)
        /// </summary>
        /// <param name="keyword">要匹配的关键字</param>
        /// <param name="topNumber">获取的数据条数</param>
        /// <param name="searchTypeCode">搜索类型编码</param>
        /// <returns>用户最多搜索的前topNumber的搜索词</returns>
        public IEnumerable <SearchedTerm> GetTops(string keyword, int topNumber, string searchTypeCode)
        {
            CountService          countService          = new CountService(TenantTypeIds.Instance().Search());
            StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Search());
            int    stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().SearchCount());
            string countType      = stageCountTypeManager.GetStageCountType(CountTypes.Instance().SearchCount(), stageCountDays);
            string countTableName = countService.GetTableName_Counts();

            var sql      = Sql.Builder;
            var whereSql = Sql.Builder;
            var orderSql = Sql.Builder;

            sql.Select("*").From("tn_SearchedTerms");
            sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, countType))
            .On("Id = c.ObjectId");
            orderSql.OrderBy("c.StatisticsCount desc");
            whereSql.Where("IsAddedByAdministrator = @0", false);

            if (!string.IsNullOrEmpty(keyword))
            {
                whereSql.Where("tn_SearchedTerms.Term like @0", StringUtility.StripSQLInjection(keyword) + "%");
            }
            if (!String.IsNullOrEmpty(searchTypeCode))
            {
                whereSql.Where("SearchTypeCode = @0", searchTypeCode);
            }
            sql.Append(whereSql).Append(orderSql);
            var primaryKeys = CreateDAO().FetchTopPrimaryKeys <SearchedTerm>(topNumber, sql);

            return(PopulateEntitiesByEntityIds(primaryKeys));
        }
Beispiel #13
0
        /// <summary>
        /// 获取前N条最热的搜索词(仅非人工干预)
        /// </summary>
        /// <param name="topNumber">获取的数据条数</param>
        /// <param name="searchTypeCode">搜索类型编码</param>
        /// <returns>用户最多搜索的前topNumber的搜索词</returns>
        public IEnumerable <SearchedTerm> GetTops(int topNumber, string searchTypeCode)
        {
            CountService          countService          = new CountService(TenantTypeIds.Instance().Search());
            StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Search());
            int    stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().SearchCount());
            string countType      = stageCountTypeManager.GetStageCountType(CountTypes.Instance().SearchCount(), stageCountDays);
            string countTableName = countService.GetTableName_Counts();

            return(GetTopEntities(topNumber, CachingExpirationType.ObjectCollection,
                                  () =>
            {
                StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.None));
                cacheKey.AppendFormat("SearchTypeCode-{0}::CountType-{1}", searchTypeCode, countType);
                return cacheKey.ToString();
            },
                                  () =>
            {
                var sql = Sql.Builder;
                var whereSql = Sql.Builder;
                var orderSql = Sql.Builder;
                sql.Select("*").From("tn_SearchedTerms");
                sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, countType))
                .On("Id = c.ObjectId");
                orderSql.OrderBy("c.StatisticsCount desc");

                if (!String.IsNullOrEmpty(searchTypeCode))
                {
                    whereSql.Where("SearchTypeCode = @0", searchTypeCode);
                }
                whereSql.Where("IsAddedByAdministrator = @0", false);
                sql.Append(whereSql).Append(orderSql);

                return sql;
            }));
        }
Beispiel #14
0
        /// <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"
            });
        }
Beispiel #15
0
        /// <summary>
        /// 采纳满意回答
        /// </summary>
        /// <remarks>
        /// 1.如果问题有悬赏则悬赏分值转移到回答者的帐户(如有交易税,需要扣除),通过EventModule实现
        /// 2.除了悬赏分的交易,回答被采纳,回答者还会获得新产生的积分,通过EventModule实现
        /// 3.注意需要发送通知给问题的关注者,通过EventModule实现
        /// 4.需要触发的事件:SetBestAnswer的OnAfter
        /// </remarks>
        /// <param name="question">问题实体</param>
        /// <param name="answer">回答实体</param>
        public void SetBestAnswer(AskQuestion question, AskAnswer answer)
        {
            if (!answer.IsBest)
            {
                answer.IsBest = true;

                //调用Service中的Update方法,以触发相应的事件,但是不更新审核状态
                this.UpdateAnswer(answer, false);
                //todo:jiangshl,改为EventModule处理
                //处理威望
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

                //用户获得威望值
                PointService pointService = new PointService();
                //提问者获取威望值
                PointItem questionPointItem = pointService.GetPointItem(PointItemKeys.Instance().Ask_AcceptedAnswer());
                ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), questionPointItem.ReputationPoints);
                //回答者获得威望
                PointItem AnswerPointItem = pointService.GetPointItem(PointItemKeys.Instance().Ask_AnswerWereAccepted());
                ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), AnswerPointItem.ReputationPoints);

                //用户计数
                ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerAcceptCount(), 1);
            }
        }
Beispiel #16
0
        /// <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"
            });
        }
Beispiel #17
0
        /// <summary>
        /// 发布问题
        /// </summary>
        /// <remarks>
        /// 1.用户提问时,悬赏的积分会被冻结,需要先扣除相应的用户积分;同时发布问题会产生新积分
        /// 2.注意在EventModule中处理动态、积分、通知、自动关注(提问者自动关注该问题);
        /// 3.使用AuditService.ChangeAuditStatusForCreate设置审核状态;
        /// 4.注意调用AttachmentService转换临时附件;
        /// 5.需要触发的事件:1)Create的OnBefore、OnAfter;2)审核状态变更;
        /// </remarks>
        /// <param name="question">问题实体</param>
        /// <returns>是否创建成功</returns>
        public bool CreateQuestion(AskQuestion question)
        {
            EventBus <AskQuestion> .Instance().OnBefore(question, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            new AuditService().ChangeAuditStatusForCreate(question.UserId, question);

            askQuestionRepository.Insert(question);
            if (question.QuestionId > 0)
            {
                //将临时附件转换为正式附件
                AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskQuestion());
                attachmentService.ToggleTemporaryAttachments(question.UserId, TenantTypeIds.Instance().AskQuestion(), question.QuestionId);

                //用户计数
                OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
                ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().QuestionCount(), 1);

                AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().AskQuestion());
                atUserService.ResolveBodyForEdit(question.Body, question.UserId, question.QuestionId);


                EventBus <AskQuestion> .Instance().OnAfter(question, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <AskQuestion, AuditEventArgs> .Instance().OnAfter(question, new AuditEventArgs(null, question.AuditStatus));
            }

            return(question.QuestionId > 0);
        }
Beispiel #18
0
        /// <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"
            });
        }
        public ActionResult ManageThreads(ManageThreadEditModel model, int pageIndex = 1, string tenantTypeId = null)
        {
            if (string.IsNullOrEmpty(tenantTypeId))
            {
                tenantTypeId = TenantTypeIds.Instance().Bar();
            }

            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);

            ViewData["BarThreads"] = barThreadService.Gets(tenantTypeId, model.GetBarThreadQuery(), model.PageSize ?? 20, pageIndex);

            ViewData["TenantType"] = tenantTypeService.Get(tenantTypeId);

            return(View(model));
        }
        public ActionResult EditGift(PointGiftEditModel model)
        {
            PointGift pointGift = model.AsPointGift();

            if (pointGift.GiftId > 0)
            {
                pointMallService.UpdateGift(pointGift);

                categoryService.ClearCategoriesFromItem(pointGift.GiftId, 0, TenantTypeIds.Instance().PointGift());
            }
            else
            {
                if (!pointMallService.CreateGift(pointGift))
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "添加商品失败!")));
                }
            }

            //添加类别
            categoryService.AddItemsToCategory(new List <long>()
            {
                pointGift.GiftId
            }, model.CategoryId);
            return(Json(new StatusMessageData(StatusMessageType.Success, model.GiftId > 0 ? "编辑商品成功!" : "添加商品成功!")));
        }
Beispiel #21
0
        /// <summary>
        /// 获取浏览过本文的人还看过的资讯列表
        /// </summary>
        /// <param name="contentItemId"></param>
        /// <param name="topNumber"></param>
        /// <returns></returns>
        public IEnumerable <ContentItem> GetVisitorAlsoVisitedItems(long contentItemId, int topNumber)
        {
            var visitService = new VisitService(TenantTypeIds.Instance().ContentItem());
            var itemIds      = visitService.GetVisitorAlsoVisitedObjectIds(contentItemId, topNumber);

            return(contentItemRepository.PopulateEntitiesByEntityIds(itemIds));
        }
        public ActionResult _ChangeGiftStatus(IEnumerable <long> giftIds, bool isEnabled)
        {
            if (giftIds == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到要操作的商品,操作失败!")));
            }
            RecommendService recommendService = new RecommendService();

            foreach (var item in giftIds)
            {
                pointMallService.SetEnabled(pointMallService.GetGift(item), isEnabled);
                if (!isEnabled)
                {
                    //删除该商品上的推荐
                    recommendService.Delete(item, TenantTypeIds.Instance().PointGift());
                }
            }
            string message;

            if (isEnabled)
            {
                message = "上架操作成功!";
            }
            else
            {
                message = "下架操作成功!";
            }
            return(Json(new StatusMessageData(StatusMessageType.Success, message)));
        }
Beispiel #23
0
        /// <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);
        }
        public ActionResult _SetTopicGroup(string topicIds = null)
        {
            SelectList topicGroups = GetTagGroupSelectList(0, TenantTypeIds.Instance().Microblog());

            ViewData["topicGroups"] = topicGroups;
            return(View());
        }
Beispiel #25
0
        /// <summary>
        /// 取消关注后更新缓存
        /// </summary>
        /// <param name="sender">关注实体</param>
        /// <param name="eventArgs">事件参数</param>
        void CancelFollowEventModule_After(FollowEntity sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                CategoryService service = new CategoryService();
                service.ClearCategoriesFromItem(sender.Id, sender.UserId, TenantTypeIds.Instance().User());

                //更新用户缓存
                ICacheService       cacheService        = DIContainer.Resolve <ICacheService>();
                RealTimeCacheHelper realTimeCacheHelper = EntityData.ForType(typeof(User)).RealTimeCacheHelper;
                if (cacheService.EnableDistributedCache)
                {
                    realTimeCacheHelper.IncreaseEntityCacheVersion(sender.UserId);
                }
                else
                {
                    string cacheKey = realTimeCacheHelper.GetCacheKeyOfEntity(sender.UserId);
                    User   user     = cacheService.Get <User>(cacheKey);
                    if (user != null && user.FollowedCount > 0)
                    {
                        user.FollowedCount--;
                    }
                }
            }
        }
Beispiel #26
0
        /// <summary>
        /// 编辑回答
        /// </summary>
        /// <remarks>
        /// 1.使用AuditService.ChangeAuditStatusForUpdate设置审核状态;
        /// 2.需要触发的事件:Update的OnBefore、OnAfter;
        /// </remarks>
        /// <param name="answer">回答实体</param>
        /// <param name="changeAuditStatusForUpdate">是否更新审核状态</param>
        public void UpdateAnswer(AskAnswer answer, bool changeAuditStatusForUpdate = true)
        {
            EventBus <AskAnswer> .Instance().OnBefore(answer, new CommonEventArgs(EventOperationType.Instance().Update()));

            AuditStatus prevAuditStatus = answer.AuditStatus;

            //设置审核状态
            if (changeAuditStatusForUpdate)
            {
                new AuditService().ChangeAuditStatusForUpdate(answer.UserId, answer);
            }

            askAnswerRepository.Update(answer);

            //更新相关问题的内容
            AskQuestion question = askQuestionRepository.Get(answer.QuestionId);

            question.LastAnswerUserId = answer.UserId;
            question.LastAnswerAuthor = answer.Author;
            question.LastAnswerDate   = answer.DateCreated;
            if (answer.IsBest)
            {
                question.Status = QuestionStatus.Resolved;
            }
            //将临时附件转换为正式附件
            AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskAnswer());

            attachmentService.ToggleTemporaryAttachments(answer.UserId, TenantTypeIds.Instance().AskAnswer(), answer.AnswerId);
            this.UpdateQuestion(question, false);
            //调用Service中的Update方法,以触发相应的事件,但是不更新审核状态
            EventBus <AskAnswer> .Instance().OnAfter(answer, new CommonEventArgs(EventOperationType.Instance().Update()));

            EventBus <AskAnswer, AuditEventArgs> .Instance().OnAfter(answer, new AuditEventArgs(prevAuditStatus, answer.AuditStatus));
        }
Beispiel #27
0
        /// <summary>
        /// 创建照片动态
        /// </summary>
        /// <param name="ActivityId"></param>
        /// <returns></returns>
        //[DonutOutputCache(CacheProfile = "Frequently")]
        public ActionResult _CreatePhoto(long ActivityId)
        {
            //实例化动态
            Activity activity = activityService.Get(ActivityId);

            if (activity == null)
            {
                return(Content(string.Empty));
            }
            ViewData["Activity"] = activity;

            //实例化照片,相册
            Album album = photoService.GetAlbum(activity.SourceId);

            if (album == null || album.PhotoCount == 0 || album.User == null)
            {
                return(Content(string.Empty));
            }

            IEnumerable <Photo> photos = photoService.GetPhotosOfAlbum(TenantTypeIds.Instance().User(), activity.SourceId, false, SortBy_Photo.DateCreated_Desc, album.LastUploadDate, 7, 1);

            ViewData["Album"] = album;

            //判断是否具有查看相册图片的权限
            ViewData["isValid"] = authorizer.Album_View(album);

            return(View(photos));
        }
Beispiel #28
0
        /// <summary>
        /// 删除回答
        /// </summary>
        /// <remarks>
        /// 1.管理员删除被采纳的回答时,需要将问题状态变更为“待解决”
        /// 2.注意维护相关问题的回答数,调用UpdateAskQuestion,AnswerCount--
        /// 3.注意需要删除动态,通过EventModule处理;
        /// 4.注意需要扣除增加的积分,通过EventModule处理;
        /// 5.注意需要删除回答者对问题的关注,通过EventModule处理;
        /// 6.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更
        /// </remarks>
        /// <param name="answer">回答实体</param>
        public void DeleteAnswer(AskAnswer answer)
        {
            EventBus <AskAnswer> .Instance().OnBefore(answer, new CommonEventArgs(EventOperationType.Instance().Delete()));

            askAnswerRepository.Delete(answer);

            //更新相关问题的内容
            AskQuestion question = askQuestionRepository.Get(answer.QuestionId);

            question.AnswerCount--;
            if (answer.IsBest)
            {
                question.Status = QuestionStatus.Unresolved;
            }
            //调用Service中的Update方法,以触发相应的事件,但是不更新审核状态
            this.UpdateQuestion(question, false);

            //用户计数
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());

            ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().AnswerCount(), -1);

            EventBus <AskAnswer> .Instance().OnAfter(answer, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <AskAnswer, AuditEventArgs> .Instance().OnAfter(answer, new AuditEventArgs(answer.AuditStatus, null));
        }
Beispiel #29
0
        /// <summary>
        /// BarThread转换成<see cref="Lucene.Net.Documents.Document"/>
        /// </summary>
        /// <param name="BarThread">发帖实体</param>
        /// <returns>Lucene.Net.Documents.Document</returns>
        public static Document Convert(BarThread barThread)
        {
            Document doc = new Document();

            //索引发帖基本信息
            doc.Add(new Field(BarIndexDocument.SectionId, barThread.SectionId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.ThreadId, barThread.ThreadId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.PostId, "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.Subject, barThread.Subject.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field(BarIndexDocument.Body, HtmlUtility.TrimHtml(barThread.GetBody(), 0).ToLower(), Field.Store.NO, Field.Index.ANALYZED));
            doc.Add(new Field(BarIndexDocument.Author, barThread.Author, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field(BarIndexDocument.IsPost, "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.DateCreated, DateTools.DateToString(barThread.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(BarIndexDocument.TenantTypeId, barThread.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED));

            //索引发帖tag
            TagService tagService = new TagService(TenantTypeIds.Instance().BarThread());

            IEnumerable <ItemInTag> itemInTags = tagService.GetItemInTagsOfItem(barThread.ThreadId);

            foreach (ItemInTag itemInTag in itemInTags)
            {
                doc.Add(new Field(BarIndexDocument.Tag, itemInTag.TagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
            }

            return(doc);
        }
Beispiel #30
0
        public ActionResult _Create_ListImages(string spaceKey, long associateId = 0)
        {
            //reply:已修改
            IUser  user         = UserContext.CurrentUser;
            string tenantTypeId = TenantTypeIds.Instance().Microblog();

            if (user == null)
            {
                return(Redirect(SiteUrls.Instance().Login()));
            }
            IEnumerable <Attachment> attachments = null;

            //reply:已修改

            if (associateId == 0)
            {
                attachments = attachmentService.GetTemporaryAttachments(user.UserId, tenantTypeId);

                //reply:已修改
            }
            else
            {
                attachments = attachmentService.GetsByAssociateId(associateId);

                //reply:已修改
            }


            //reply:已修改


            //reply:已修改

            return(View(attachments));
        }