예제 #1
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);
        }
예제 #2
0
        private static async Task <RepositoryResponse <PaginationModel <TView> > > SearchPostByValue <TView>(
            Expression <Func <MixDatabaseDataValue, bool> > valPredicate,
            SearchPostQueryModel searchPostData,
            MixCmsContext context,
            IDbContextTransaction transaction)
            where TView : ViewModelBase <MixCmsContext, MixPost, TView>
        {
            var allPostIds = IQueryableHelper.GetPostIdsByValue(
                valPredicate,
                context,
                searchPostData.Specificulture,
                searchPostData.PostType);

            var resultIds = searchPostData.PagingData.OrderBy.StartsWith("additionalData.")
                ? GetSortedIdsByValue(allPostIds, context, searchPostData.PagingData, searchPostData.Specificulture, searchPostData.PostType)
                : searchPostData.PageId.HasValue
                    ? GetSortedIdsByPage(allPostIds, searchPostData, context, transaction)
                    : allPostIds.Skip(searchPostData.PagingData.PageIndex * searchPostData.PagingData.PageSize)
                            .Take(searchPostData.PagingData.PageSize)
                            .Select(p => int.Parse(p)).ToList();


            var getPosts = (await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetModelListByAsync(
                                m => resultIds.Any(p => p == m.Id) && m.Specificulture == searchPostData.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  = searchPostData.PagingData.PageIndex,
                    PageSize   = searchPostData.PagingData.PageSize,
                    TotalItems = total,
                    TotalPage  = (int)Math.Ceiling((double)total / searchPostData.PagingData.PageSize)
                }
            };

            return(result);
        }