예제 #1
0
 private static List <int> GetSortedIdsByValue(IQueryable <string> allPostIds, MixCmsContext context, PagingRequest pagingData, string specificulture, string postType)
 {
     return(IQueryableHelper.SortParentIds(allPostIds,
                                           context,
                                           pagingData,
                                           specificulture,
                                           postType)
            .AsEnumerable()
            .Select(p => int.Parse(p))
            .ToList());
 }
예제 #2
0
        private static async Task <RepositoryResponse <PaginationModel <TView> > > SearchPostByValue <TView>(
            Expression <Func <MixDatabaseDataValue, bool> > valPredicate,
            PagingRequest pagingData,
            string postType,
            string specificulture,
            MixCmsContext context,
            IDbContextTransaction transaction)
            where TView : ViewModelBase <MixCmsContext, MixPost, TView>
        {
            var allPostIds = IQueryableHelper.GetPostIdsByValue(
                valPredicate,
                context,
                specificulture,
                postType);
            var resultIds = IQueryableHelper.SortParentIds(
                allPostIds.Skip(pagingData.PageIndex * pagingData.PageSize)
                .Take(pagingData.PageSize),
                context,
                pagingData,
                specificulture,
                postType)
                            .AsEnumerable()
                            .Select(p => int.Parse(p))
                            .ToList();

            var getPosts = (await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetModelListByAsync(
                                m => resultIds.Any(p => p == m.Id) && m.Specificulture == specificulture,
                                context,
                                transaction));
            var items = getPosts.Data.OrderBy(
                m => resultIds.IndexOf((int)ReflectionHelper.GetPropertyValue(m, "Id"))).ToList();
            var total  = allPostIds.Count();
            var result = new RepositoryResponse <PaginationModel <TView> >()
            {
                IsSucceed = true,
                Data      = new PaginationModel <TView>()
                {
                    Items      = items,
                    PageIndex  = pagingData.PageIndex,
                    PageSize   = pagingData.PageSize,
                    TotalItems = total,
                    TotalPage  = (int)Math.Ceiling((double)total / pagingData.PageSize)
                }
            };

            return(result);
        }