public static async Task <RepositoryResponse <PaginationModel <TView> > > GetListPostByAdditionalField <TView>( string fieldName, object fieldValue, string culture, MixDataType dataType , MixCompareOperatorKind filterType = MixCompareOperatorKind.Equal , string orderByPropertyName = null, Heart.Enums.DisplayDirection direction = Heart.Enums.DisplayDirection.Asc, int?pageSize = null, int?pageIndex = null , 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 { var result = new RepositoryResponse <PaginationModel <TView> >() { IsSucceed = true, Data = new PaginationModel <TView>() { PageIndex = pageIndex.HasValue ? pageIndex.Value : 0, PageSize = pageSize } }; // Get Value Predicate By Type Expression <Func <MixDatabaseDataValue, bool> > valPredicate = m => m.MixDatabaseName == MixConstants.MixDatabaseName.ADDITIONAL_FIELD_POST && m.MixDatabaseColumnName == fieldName; var pre = GetValuePredicate(fieldValue.ToString(), filterType, dataType); if (pre != null) { valPredicate = valPredicate.AndAlso(pre); } var query = context.MixDatabaseDataValue.Where(valPredicate).Select(m => m.DataId).Distinct(); var dataIds = query.ToList(); var relatedQuery = context.MixDatabaseDataAssociation.Where( m => m.ParentType == MixDatabaseParentType.Post && m.Specificulture == culture && dataIds.Any(d => d == m.DataId)); var postIds = relatedQuery.Select(m => int.Parse(m.ParentId)).Distinct().AsEnumerable().ToList(); result = await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetModelListByAsync( m => m.Specificulture == culture && postIds.Any(p => p == m.Id) , orderByPropertyName, direction , pageSize ?? 100, pageIndex ?? 0 , null, null , context, transaction); return(result); } catch (Exception ex) { return(UnitOfWorkHelper <MixCmsContext> .HandleException <PaginationModel <TView> >(ex, isRoot, transaction)); } finally { if (isRoot) { //if current Context is Root context.Dispose(); } } }
public static async Task <RepositoryResponse <PaginationModel <Lib.ViewModels.MixDatabaseDatas.ReadMvcViewModel> > > GetAttributeDataListBySet( HttpContext context , string mixDatabaseName , string culture = null , Heart.Enums.DisplayDirection direction = DisplayDirection.Desc , MixCmsContext _context = null, IDbContextTransaction _transaction = null ) { var result = await ViewModels.MixDatabaseDatas.Helper.FilterByKeywordAsync <ViewModels.MixDatabaseDatas.ReadMvcViewModel>( context.Request, culture, mixDatabaseName); return(result); }
public static async Task <RepositoryResponse <PaginationModel <Lib.ViewModels.MixPagePosts.ReadViewModel> > > GetPostListByPageId( HttpContext context , int pageId , string keyword = null , string culture = null , string orderBy = "CreatedDateTime" , Heart.Enums.DisplayDirection direction = DisplayDirection.Desc , MixCmsContext _context = null, IDbContextTransaction _transaction = null ) { int.TryParse(context.Request.Query[MixRequestQueryKeywords.Page], out int page); int.TryParse(context.Request.Query[MixRequestQueryKeywords.PageSize], out int pageSize); page = (page > 0) ? page : 1; var result = await ViewModels.MixPosts.Helper.GetPostListByPageId <Lib.ViewModels.MixPagePosts.ReadViewModel>( pageId, keyword, culture, orderBy, direction, pageSize, page - 1, _context, _transaction); result.Data.Items.ForEach(m => m.LoadPost(_context, _transaction)); return(result); }
public static async Task <RepositoryResponse <PaginationModel <TView> > > GetPostListByPageId <TView>( int pageId , string keyword = null , string culture = null , string orderByPropertyName = "CreatedDateTime" , Heart.Enums.DisplayDirection direction = Heart.Enums.DisplayDirection.Desc , int?pageSize = null, int?pageIndex = null , MixCmsContext _context = null, IDbContextTransaction _transaction = null) where TView : ViewModelBase <MixCmsContext, MixPagePost, TView> { UnitOfWorkHelper <MixCmsContext> .InitTransaction(_context, _transaction, out MixCmsContext context, out IDbContextTransaction transaction, out bool isRoot); try { culture = culture ?? MixService.GetConfig <string>("DefaultCulture"); var result = await DefaultRepository <MixCmsContext, MixPagePost, TView> .Instance.GetModelListByAsync( m => m.Specificulture == culture && m.PageId == pageId && (string.IsNullOrEmpty(keyword) || (EF.Functions.Like(m.MixPost.Title, $"%{keyword}%")) || (EF.Functions.Like(m.MixPost.Excerpt, $"%{keyword}%")) || (EF.Functions.Like(m.MixPost.Content, $"%{keyword}%")) ) , orderByPropertyName, direction, pageSize, pageIndex , _context : context, _transaction : transaction ); return(result); } 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); } } }
public static async Task <RepositoryResponse <PaginationModel <TView> > > SearchPostByField <TView>( string fieldName, string value , string culture = null , string orderByPropertyName = "CreatedDateTime", Heart.Enums.DisplayDirection direction = Heart.Enums.DisplayDirection.Desc , int?pageSize = null, int?pageIndex = 0 , 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 { culture ??= MixService.GetConfig <string>(MixAppSettingKeywords.DefaultCulture); var result = new RepositoryResponse <PaginationModel <TView> >() { IsSucceed = true, Data = new PaginationModel <TView>() { PageIndex = pageIndex.HasValue ? pageIndex.Value : 0, PageSize = pageSize } }; var tasks = new List <Task <RepositoryResponse <TView> > >(); // Get Value var dataIds = await context.MixDatabaseDataValue.Where( m => m.MixDatabaseName == MixConstants.MixDatabaseName.ADDITIONAL_FIELD_POST && m.Specificulture == culture && EF.Functions.Like(m.StringValue, value) && m.MixDatabaseColumnName == fieldName) .Select(m => m.DataId)?.ToListAsync(); if (dataIds != null && dataIds.Count > 0) { var getRelatedData = await MixDatabaseDataAssociations.ReadViewModel.Repository.GetModelListByAsync( m => dataIds.Contains(m.DataId) , orderByPropertyName, direction, pageSize, pageIndex , _context : context, _transaction : transaction ); if (getRelatedData.IsSucceed) { foreach (var item in getRelatedData.Data.Items) { if (int.TryParse(item.ParentId, out int postId)) { var getData = await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetSingleModelAsync( m => m.Specificulture == item.Specificulture && m.Id == postId , context, transaction); if (getData.IsSucceed) { result.Data.Items.Add(getData.Data); } } } result.Data.TotalItems = getRelatedData.Data.TotalItems; result.Data.TotalPage = getRelatedData.Data.TotalPage; } } return(result); } 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); } } }
public static async Task <RepositoryResponse <PaginationModel <TView> > > SearchPostByIds <TView>( string keyword , List <string> dataIds , List <string> nestedIds , List <int> pageIds = null , string culture = null , string orderByPropertyName = "CreatedDateTime" , Heart.Enums.DisplayDirection direction = Heart.Enums.DisplayDirection.Desc , int?pageSize = null, int?pageIndex = null , 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 { culture = culture ?? MixService.GetConfig <string>("DefaultCulture"); Expression <Func <MixPost, bool> > postPredicate = m => m.Specificulture == culture && (string.IsNullOrEmpty(keyword) || (EF.Functions.Like(m.Title, $"%{keyword}%")) || (EF.Functions.Like(m.Excerpt, $"%{keyword}%")) || (EF.Functions.Like(m.Content, $"%{keyword}%"))); var searchPostByDataIds = SearchPostByDataIdsPredicate(dataIds, nestedIds, culture, context); postPredicate = postPredicate.AndAlsoIf(searchPostByDataIds != null, searchPostByDataIds); if (pageIds != null && pageIds.Count > 0) { var searchPostByPageIds = SearchPostByPageIdsPredicate(pageIds, culture, context); postPredicate = searchPostByPageIds.AndAlso(postPredicate); } if (!typeof(MixPost).GetProperties().Any(p => p.Name.ToLower() == orderByPropertyName.ToLower())) { var postIds = context.MixPost.Where(postPredicate).Select(p => p.Id); var orderedPostIds = context.MixDatabaseDataAssociation.Where( m => m.Specificulture == culture && postIds.Any(p => p.ToString() == m.ParentId)) .Join(context.MixDatabaseDataValue, r => r.DataId, v => v.DataId, (r, v) => new { r, v }) .OrderBy(rv => rv.v.StringValue) .Select(rv => rv.r.ParentId); postPredicate = p => orderedPostIds.Distinct().Any(o => o == p.Id.ToString() && p.Specificulture == culture); } return(await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetModelListByAsync( postPredicate , orderByPropertyName, direction , pageSize, pageIndex , _context : context, _transaction : 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); } } }
public static async Task <RepositoryResponse <PaginationModel <TView> > > GetPostListByDataIds <TView>( List <string> dataIds , string culture = null , string orderByPropertyName = "CreatedDateTime" , Heart.Enums.DisplayDirection direction = Heart.Enums.DisplayDirection.Desc , int?pageSize = null, int?pageIndex = null , 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 { culture = culture ?? MixService.GetConfig <string>("DefaultCulture"); var result = new RepositoryResponse <PaginationModel <TView> >(); Expression <Func <MixDatabaseDataAssociation, bool> > predicate = m => m.Specificulture == culture && dataIds.Contains(m.DataId) && m.ParentType == MixDatabaseParentType.Post; foreach (var id in dataIds) { Expression <Func <MixDatabaseDataAssociation, bool> > pre = m => m.DataId == id; predicate = predicate.AndAlso(pre); } var getRelatedData = await MixDatabaseDataAssociations.ReadViewModel.Repository.GetModelListByAsync( predicate , orderByPropertyName = "CreatedDateTime", direction, pageSize, pageIndex , _context : context, _transaction : transaction ); if (getRelatedData.IsSucceed) { foreach (var item in getRelatedData.Data.Items) { if (int.TryParse(item.ParentId, out int postId)) { var getData = await DefaultRepository <MixCmsContext, MixPost, TView> .Instance.GetSingleModelAsync( m => m.Specificulture == item.Specificulture && m.Id == postId , context, transaction); if (getData.IsSucceed) { result = new RepositoryResponse <PaginationModel <TView> >() { IsSucceed = true, Data = new PaginationModel <TView>() { Items = new List <TView>(), PageIndex = pageIndex ?? 0, PageSize = pageSize } }; result.Data.Items.Add(getData.Data); } } } result.Data.TotalItems = getRelatedData.Data.TotalItems; result.Data.TotalPage = getRelatedData.Data.TotalPage; } return(result); } 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); } } }
public static async Task <RepositoryResponse <PaginationModel <TView> > > GetPostListByValueIds <TView>( List <string> valueIds , string culture = null , string orderByPropertyName = "CreatedDateTime" , Heart.Enums.DisplayDirection direction = Heart.Enums.DisplayDirection.Desc , int?pageSize = null, int?pageIndex = null , 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 { culture = culture ?? MixService.GetConfig <string>("DefaultCulture"); var result = new RepositoryResponse <PaginationModel <TView> >() { IsSucceed = true, Data = new PaginationModel <TView>() { PageIndex = pageIndex.HasValue ? pageIndex.Value : 0, PageSize = pageSize } }; // Get Data Expression <Func <MixDatabaseDataValue, bool> > predicate = m => m.Specificulture == culture && m.Status == MixContentStatus.Published; foreach (var item in valueIds) { Expression <Func <MixDatabaseDataValue, bool> > pre = m => m.Id == item; predicate = predicate.AndAlso(pre); } var getVal = await MixDatabaseDataValues.ReadViewModel.Repository.GetModelListByAsync(predicate, context, transaction); if (getVal.IsSucceed) { var dataIds = getVal.Data.Select(m => m.DataId).Distinct(); if (dataIds.Count() == 1) { result = await GetPostListByDataIds <TView>( dataIds : dataIds.ToList(), culture : culture, orderByPropertyName : orderByPropertyName, direction : direction, pageSize : pageSize, pageIndex : pageIndex, _context : context, _transaction : transaction); } //var query = context.MixRelatedAttributeData.Where(m=> m.Specificulture == culture // && m.Id == getVal.Data.DataId && m.ParentId == parentId && m.ParentType == (int) MixEnums.MixDatabaseDataType.Post) // .Select(m => m.ParentId).Distinct().ToList(); } return(result); } 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); } } }