Beispiel #1
0
 public async Task <List <ContentEntry> > GetContentListByCategoryName(string categoryName, int num)
 {
     return(await ContentAccessor.All <ContentEntry>().Where(x => x.Category.Name == categoryName & !x.IsFaq)
            .OrderByDescending(x => x.IsTop)
            .OrderByDescending(x => x.Order)
            .OrderByDescending(x => x.CreateTime)
            .Take(num)
            .ToListAsync());
 }
Beispiel #2
0
        public async Task <Tuple <List <ContentEntry>, int> > GetContentListByCategoryName(string categoryName, int skipCount, int pageSize)
        {
            var dbSet       = ContentAccessor.All <ContentEntry>().Where(x => x.Category.Name == categoryName & !x.IsFaq);
            var contetnList = await dbSet
                              .Include("MediaResource")
                              .OrderByDescending(x => x.IsTop)
                              .OrderByDescending(x => x.Order)
                              .OrderByDescending(x => x.CreateTime)
                              .Skip(skipCount)
                              .Take(pageSize)
                              .ToListAsync();

            var total = await dbSet.CountAsync();

            return(Tuple.Create(contetnList, total));
            //throw new NotImplementedException();
        }
Beispiel #3
0
        public async Task CreateMultiContent(Guid pid, string contentName, int count)
        {
            var category = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == pid);

            var contentList = new List <ContentEntry>();

            for (int i = 1; i <= count; i++)
            {
                contentList.Add(new ContentEntry
                {
                    Category   = category,
                    Title      = $"{contentName} 第{i}话",
                    Order      = i,
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid()
                });
            }
            await ContentAccessor.All <ContentEntry>().AddRangeAsync(contentList);

            await ContentAccessor.SaveAsync();
        }
Beispiel #4
0
        public async Task <Dictionary <Tuple <Guid, string>, List <ContentEntry> > > GetContentWithCategory(string pCategoryName, int pageSize)
        {
            var categoryList = await ContentAccessor.All <Categories>()
                               .Where(x => x.ParentCategory.Name == pCategoryName)
                               .ToListAsync();

            var dictContent = new Dictionary <Tuple <Guid, string>, List <ContentEntry> >();

            foreach (var categoryItem in categoryList)
            {
                var contentList = await ContentAccessor.All <ContentEntry>().Where(x => x.Category.Id == categoryItem.Id).ToListAsync();

                var tuple = Tuple.Create(categoryItem.Id, categoryItem.Name);
                dictContent.Add(tuple, contentList);
            }
            return(dictContent);

            //var contentList = await ContentAccessor.All<ContentEntry>()
            //                                .Where(x => x.Category.Name == pCategoryName)
            //                                .Select(x => new
            //                                {
            //                                    Category = x.Category,
            //                                    Content = x
            //                                })
            //                                .GroupBy(x => x.Category.Name)
            //                                .ToDictionaryAsync(x => x.Key, c => c.Select(v => v.Content));
            //var cateList = ContentAccessor.All<Categories>()
            //                            .Where(x => x.ParentCategory.Name == pCategoryName)
            //                            .Select(x => new
            //                            {
            //                                Category = x,
            //                                ContentList = x.ContentList.Take(pageSize).ToList()
            //                            })
            //                            .GroupBy(x => x.Category.Name);

            //return await cateList.ToDictionaryAsync(x => x.Key, c => c.Select(v => v.ContentList));
        }
Beispiel #5
0
        public async Task <List <PostEntryOutputViewModel> > GetCategoryCommentExtPostEntry(Guid cateId, int skipCount, int pageSize)
        {
            //通过cate 名找到话题
            var postEntryMapCategory = await ContentAccessor.ListOrderByDescendingAsync <CategoryPostEntryMapping>(x => x.CategoryId == cateId);

            var postEntryList = await ContentAccessor.ListOrderByDescendingAsync <PostEntry>(x => postEntryMapCategory.Any(c => c.PostEntryId == x.Id), skipCount, pageSize, "UserAccountEntry", "UserAccountEntry.Profile");

            //var postentrySubComments = await ContentAccessor.All<PostEntry>().Where(x => postEntryList.Select(c => c.Id).Any(c => c == x.Id))
            //    .Include("PostEntryCommentList.UserAccount")
            //    .Select(x => new
            //    {
            //        PostId = x.Id,
            //        SubComments = x.PostEntryCommentList.Select(c => new
            //        {
            //             c
            //             c.CreateTime
            //        }).Take(2).OrderByDescending(c => c.CreateTime).ToList(),
            //        SubCommentsNum = x.PostEntryCommentList.Count()
            //    }).ToListAsync();
            var postentrySubComments = ContentAccessor.All <PostEntryComments>()
                                       .Where(x => postEntryList.Select(c => c.Id).Any(c => c == x.PostEntryId))
                                       .Include("UserAccount")
                                       .Include("ParentComment")
                                       .Include("ParentComment.UserAccount")
                                       .OrderByDescending(x => x.CreateTime)
                                       .Take(2)
                                       .GroupBy(x => x.PostEntryId)
                                       .ToList();
            //var postentrySubCommentNum = new Dictionary<Guid, int>();
            //postEntryList.ToList().ForEach(item =>
            //{

            //});
            var postentrtSubCommentsNum = await ContentAccessor.All <PostEntry>()
                                          .Where(x => postEntryList.Select(c => c.Id).Any(c => c == x.Id))
                                          .Select(x => new
            {
                x.Id,
                Count = x.PostEntryCommentList.Count()
            })
                                          .ToListAsync();



            var postEntryOutput = new List <PostEntryOutputViewModel>();

            postEntryList.ToList().ForEach(item =>
            {
                var subComments   = postentrySubComments.FirstOrDefault(x => x.Key == item.Id)?.ToList();
                var subCommentNum = postentrtSubCommentsNum.FirstOrDefault(x => x.Id == item.Id)?.Count ?? 0;
                postEntryOutput.Add(new PostEntryOutputViewModel
                {
                    Id      = item.Id,
                    LikeSum = item.LikeSum,
                    Order   = item.Order,
                    PostEntryCommentList    = subComments,
                    PostEntryCommentListNum = subCommentNum,
                    PostEntryTopic          = item.PostEntryTopic,
                    TextContent             = item.TextContent,
                    TimeStamp        = item.TimeStamp,
                    UserAccountEntry = item.UserAccountEntry
                });
            });
            return(postEntryOutput);
        }