private static RepositoryResponse <PaginationModel <TView> > GetSortedPostByValue <TView>( Expression <Func <MixPost, bool> > predicate, SearchPostQueryModel searchPostData, MixCmsContext context, IDbContextTransaction transaction) where TView : ViewModelBase <MixCmsContext, MixPost, TView> { var total = context.MixPost.Count(predicate); var allPostIds = context.MixPost.Where(predicate) .AsEnumerable() .Select(m => m.Id); var posts = IQueryableHelper.GetSortedPost(allPostIds, context, searchPostData).ToList(); return(new RepositoryResponse <PaginationModel <TView> >() { IsSucceed = true, Data = new PaginationModel <TView>() { Items = DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetCachedData(posts, context, transaction), PageSize = searchPostData.PagingData.PageSize, PageIndex = searchPostData.PagingData.PageIndex } }); }
public static async Task <RepositoryResponse <PaginationModel <TView> > > SearchPosts <TView>( SearchPostQueryModel searchPostData, MixCmsContext _context = null, IDbContextTransaction _transaction = null) where TView : ViewModelBase <MixCmsContext, MixPost, TView> { UnitOfWorkHelper <MixCmsContext> .InitTransaction(_context, _transaction, out MixCmsContext context, out IDbContextTransaction transaction, out bool isRoot); try { Expression <Func <MixDatabaseDataValue, bool> > valPredicate = null; valPredicate = valPredicate.AndAlsoIf( !string.IsNullOrEmpty(searchPostData.Category), Expressions.GetMetaExpression(MixDatabaseNames.SYSTEM_CATEGORY, searchPostData.Category, searchPostData.Specificulture)); valPredicate = valPredicate.AndAlsoIf( !string.IsNullOrEmpty(searchPostData.Tag), Expressions.GetMetaExpression(MixDatabaseNames.SYSTEM_TAG, searchPostData.Tag, searchPostData.Specificulture)); if (valPredicate != null) { return(await SearchPostByValue <TView>(valPredicate, searchPostData.PagingData, searchPostData.PostType, searchPostData.Specificulture, context, transaction)); } else { Expression <Func <MixPost, bool> > predicate = BuildPostExpression(searchPostData); if (searchPostData.PagingData.OrderBy.StartsWith("additionalData.")) { var total = context.MixPost.Count(predicate); var allPostIds = context.MixPost.Where(predicate) .AsEnumerable() .Select(m => m.Id); var posts = IQueryableHelper.GetSortedPost(allPostIds, context, searchPostData).ToList(); return(new RepositoryResponse <PaginationModel <TView> >() { IsSucceed = true, Data = new PaginationModel <TView>() { Items = DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetCachedData(posts, context, transaction), PageSize = searchPostData.PagingData.PageSize, PageIndex = searchPostData.PagingData.PageIndex } }); } return(await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetModelListByAsync( predicate, searchPostData.PagingData.OrderBy, searchPostData.PagingData.Direction, searchPostData.PagingData.PageSize, searchPostData.PagingData.PageIndex, null, null, context, transaction)); } } catch (Exception ex) { return(UnitOfWorkHelper <MixCmsContext> .HandleException <PaginationModel <TView> >(ex, isRoot, transaction)); } finally { if (isRoot) { //if current Context is Root UnitOfWorkHelper <MixCmsContext> .CloseDbContext(ref context, ref transaction); } } }