コード例 #1
0
        public ActionResult AtMeComments(string spaceKey, int? pageIndex, string tenantTypeId = "")
        {
            pageResourceManager.InsertTitlePart("@我的评论");

            long userId = UserIdToUserNameDictionary.GetUserId(spaceKey);
            AtUserService service = new AtUserService(TenantTypeIds.Instance().Comment());
            PagingDataSet<long> objectIds = service.GetPagingAssociateIds(userId, pageIndex ?? 1);

            IList<Comment> commentLists = new List<Comment>();
            foreach (var commentId in objectIds)
            {
                Comment comment = commentService.Get(commentId);
                if (comment != null)
                {
                    commentLists.Add(comment);
                }
            }
            if (!string.IsNullOrEmpty(tenantTypeId))
            {
                commentLists = commentLists.Where(n => n.TenantTypeId == tenantTypeId).ToList();
            }

            PagingDataSet<Comment> comments = new PagingDataSet<Comment>(commentLists)
            {
                PageIndex = pageIndex ?? 1,
                PageSize = objectIds.PageSize,
                TotalRecords = objectIds.TotalRecords
            };

            Dictionary<long, TenantType> commentId_tenantType = new Dictionary<long, TenantType>();
            Dictionary<long, CommentedObject> commentedObject = new Dictionary<long, CommentedObject>();
            Dictionary<long, Comment> commentId_parentComment = new Dictionary<long, Comment>();

            //排除掉被禁用的应用
            var tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Comment()).Where(n => n.TenantTypeId != "101202" && n.TenantTypeId != "200101");
            List<TenantType> tennatType_List = new List<TenantType>();
            foreach (var item in tenantTypes)
            {
                if (applicationService.Get(item.ApplicationId).IsEnabled)
                {
                    tennatType_List.Add(item);
                }
            }
            Dictionary<string, string> tenantTypeDic = tennatType_List.ToDictionary(k => k.TenantTypeId, v => v.Name);

            foreach (var comment in comments)
            {
                TenantType tenantType = tenantTypeService.Get(comment.TenantTypeId);
                if (comment.TenantTypeId != TenantTypeIds.Instance().Group())
                {
                    commentId_tenantType[comment.Id] = tenantType;
                }

                ICommentUrlGetter commentUrlGetter = CommentUrlGetterFactory.Get(comment.TenantTypeId);
                if (commentUrlGetter != null && comment.CommentedObjectId != 0)
                {
                    CommentedObject comment_object = commentUrlGetter.GetCommentedObject(comment.CommentedObjectId);
                    if (comment_object != null)
                    {
                        commentedObject[comment.Id] = comment_object;
                    }

                }
                if (comment.ParentId != 0)
                {
                    commentId_parentComment[comment.Id] = commentService.Get(comment.ParentId);
                }
            }
            ViewData["tenantTypeDic"] = tenantTypeDic;
            ViewData["commentId_tenantType"] = commentId_tenantType;
            ViewData["commentedObject"] = commentedObject;
            ViewData["commentId_parentComment"] = commentId_parentComment;

            return View(comments);
        }
コード例 #2
0
        /// <summary>
        /// 获取提到用户的微博分页集合
        /// </summary>
        /// <param name="userName">被提到的用户Id</param>
        /// <param name="pageIndex">页码</param>
        /// <returns></returns>
        public PagingDataSet<MicroblogEntity> GetMicroblogsByReferredUser(long userId, int pageIndex)
        {
            AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().Microblog());

            PagingDataSet<long> pagingIds = atUserService.GetPagingAssociateIds(userId, pageIndex);

            if (pagingIds != null)
            {

                PagingDataSet<MicroblogEntity> pds = new PagingDataSet<MicroblogEntity>(microblogRepository.PopulateEntitiesByEntityIds(pagingIds));
                pds.PageIndex = pagingIds.PageIndex;
                pds.PageSize = pagingIds.PageSize;
                pds.TotalRecords = pagingIds.TotalRecords;

                return pds;
            }

            return null;
        }