Beispiel #1
0
 public PageRegistrationSetup(IPageConfig config)
 {
     Name     = config.Name;
     Alias    = config.Alias;
     Icon     = config.Icon;
     Sections = config.SectionRegistrations.Select(x => new CustomTypeRegistrationSetup(x) as ITypeRegistration).ToList();
 }
Beispiel #2
0
 protected PageAbstract(
     ICacheRepository cacheRepository,
     IQueryable <TValue> listEntities,
     IPageConfig config
     ) : base(listEntities, config, cacheRepository)
 {
 }
 public virtual async Task <IPage <TValue> > GetPageAsync(
     IPageConfig config,
     Expression <Func <TValue, bool> > predicate,
     bool EnableAsNoTracking) =>
 await Task.Run(() => GetAllQueryable(EnableAsNoTracking)
                .Where(predicate)
                .ToPage <TValue>(_cacheService, config));
 public virtual async Task <IPage <TValue> > GetPageAsync(
     IPageConfig config,
     TFilter filter,
     bool EnableAsNoTracking) =>
 await Task.Run(() => GetAllQueryable(EnableAsNoTracking)
                .Where(filter.GenerateLambda <TValue, TFilter>(_cacheService))
                .ToPage <TValue>(_cacheService, config));
 private static void ValidateCtor(int count, IPageConfig config)
 {
     config.IsNull(nameof(ValidateCtor), nameof(config));
     if (count < 1)
     {
         Validation.HandleNullError($"ClassName: {nameof(ValidateCtor)} {Environment.NewLine}Message: The listEntities is empty!");
     }
 }
 public void StartCtor(
     IPageConfig config,
     IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     Func <IEnumerable <object>, IEnumerable <TResult> > mapping)
 {
     ThrowErrorIf.IsNullValue(mapping, nameof(mapping), typeof(PageAbstract <,>).Name);
     Mapping = mapping;
 }
 protected PageFilterAbstract(
     IPageConfig config,
     IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     Func <IEnumerable <object>, IEnumerable <TResult> > mapping
     ) : base(listEntities, config, cacheRepository)
 {
     StartCtor(config, listEntities, cacheRepository, mapping);
 }
 public Page(
     ICacheRepository cacheRepository,
     IQueryable <TValue> listEntities,
     IPageConfig config) :
     base(
         cacheRepository,
         listEntities,
         config)
 {
 }
        public static async Task <Expression <Func <TValue, object> > > CreateGenericOrderBy <TValue>(
            this IPageConfig pageConfig,
            ICacheRepository cacheRepository,
            CancellationToken token)
        {
            var order = pageConfig.Order;

            return(await GetGenericExpression <TValue>(order, cacheRepository, token).
                   ConfigureAwait(false));
        }
 /// <summary>
 /// Paginate entity TValue, default values: pageStartInOne: false, sort= ASC, order=Id, size=10
 /// </summary>
 /// <param name="listEntities">IQueryable from entity TValue</param>
 /// <param name="config">Config from Page</param>
 /// <typeparam name="TValue">Entity E</typeparam>
 /// <returns>Paginated List E</returns>
 public static IPage <TValue> ToPage <TValue>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     IPageConfig config)
     where TValue : class =>
 ToPage(
     listEntities,
     cacheRepository,
     config,
     false);
Beispiel #11
0
 /// <summary>Converts to page.</summary>
 /// <typeparam name="TValue">The type of the value.</typeparam>
 /// <param name="listEntities">The list entities.</param>
 /// <param name="cacheRepository">The cache repository.</param>
 /// <param name="config">The configuration.</param>
 /// <returns></returns>
 public static async Task <IPage <TValue> > ToPage <TValue>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     IPageConfig config,
     CancellationToken token)
     where TValue : class =>
 await new Page <TValue>(
     cacheRepository,
     listEntities,
     config).Init(token).
 ConfigureAwait(false);
        public virtual async Task <IPage <TValue> > GetPageAsync(
            IPageConfig config,
            bool notTracking,
            CancellationToken token)
        {
            ThrowErrorIf.IsNullValue(config, nameof(config), nameof(GetPageAsync));

            await CreateQuery(notTracking, token).ConfigureAwait(false);

            return(await Query.ToPage(CacheService, config, token).
                   ConfigureAwait(false));
        }
Beispiel #13
0
        public async Task <IPage <TReturn> > GetPageAsync <TReturn>(
            IPageConfig config,
            bool notTracking,
            Func <IEnumerable <object>, IEnumerable <TReturn> > mapper,
            CancellationToken token) where TReturn : class
        {
            await CreateQuery(notTracking, token).ConfigureAwait(false);

            return(await Query.
                   ToPageFiltered <TValue, TFilter, TReturn>(CacheService, mapper, config, token).
                   ConfigureAwait(false));
        }
 /// <summary>
 /// Paginate entity TValue, default values: sort= ASC, order=Id, size=10
 /// </summary>
 /// <param name="listEntities">IQueryable from entity TValue</param>
 /// <param name="config">Config from Page</param>
 /// <param name="pageStartInOne">If Page starts on index 1</param>
 /// <typeparam name="TValue"></typeparam>
 /// <returns></returns>
 public static IPage <TValue> ToPage <TValue>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     IPageConfig config,
     bool pageStartInOne)
     where TValue : class =>
 ToPage(
     listEntities,
     cacheRepository,
     config,
     pageStartInOne,
     "ASC");
 /// <summary>
 /// Paginate entity TValue mapping result to TResult by Func mapperTo,, default values: pageStartInOne: false, sort= ASC, order=Id, size=10
 /// </summary>
 /// <param name="listEntities">IQueryable from entity TValue</param>
 /// <param name="config">Config from Page</param>
 /// <typeparam name="TValue">Database type</typeparam>
 /// <typeparam name="TResult">Return type</typeparam>
 public static IPage <TResult> ToPage <TValue, TResult>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     Func <IEnumerable <TValue>, IEnumerable <TResult> > mapperTo,
     IPageConfig config)
     where TValue : class
     where TResult : class =>
 ToPage(
     listEntities,
     cacheRepository,
     mapperTo,
     config,
     false);
Beispiel #16
0
 /// <summary>Converts to page.</summary>
 /// <typeparam name="TValue">The type of the value.</typeparam>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="listEntities">The list entities.</param>
 /// <param name="cacheRepository">The cache repository.</param>
 /// <param name="config">The configuration.</param>
 /// <param name="mapping">The mapping.</param>
 /// <returns></returns>
 public static async Task <IPage <TResult> > ToPage <TValue, TResult>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     IPageConfig config,
     Func <IEnumerable <object>, IEnumerable <TResult> > mapping,
     CancellationToken token)
     where TValue : class
     where TResult : class =>
 await new Page <TValue, TResult>(
     cacheRepository,
     listEntities,
     config,
     mapping).Init(token).
 ConfigureAwait(false);
 /// <summary>
 /// Paginate entity TValue, default values: order=Id, size=10
 /// </summary>
 /// <param name="listEntities">IQueryable from entity TValue</param>
 /// <param name="config">Config from Page</param>
 /// <param name="pageStartInOne">If Page starts on index 1</param>
 /// <param name="defaultSort">Default value to sort ("ASC" or "DESC")</param>
 /// <typeparam name="TValue"></typeparam>
 /// <returns></returns>
 public static IPage <TValue> ToPage <TValue>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     IPageConfig config,
     bool pageStartInOne,
     string defaultSort)
     where TValue : class =>
 ToPage(
     listEntities,
     cacheRepository,
     config,
     pageStartInOne,
     defaultSort,
     "Id");
        public IResolvedSetup <IEnumerable <ITreeElementSetup> > ResolveSetup(IEnumerable <ITreeElementConfig> config, ICollectionSetup?collection = default)
        {
            return(new ResolvedSetup <IEnumerable <ITreeElementSetup> >(config.Select(corp =>
            {
                var type = corp switch
                {
                    IPageConfig page => PageType.Page,
                    _ => PageType.Collection
                };

                return new TreeElementSetup(corp.Alias, type)
                {
                    RootVisibility = (corp as CollectionConfig)?.TreeView?.RootVisibility ?? default
                };
            }) ?? Enumerable.Empty <ITreeElementSetup>(),
                                                                        true));
        }
 /// <summary>
 /// Paginate entity TValue mapping result to TResult by Func mapperTo, default values: order=Id, size=10
 /// </summary>
 /// <param name="listEntities">IQueryable from entity TValue</param>
 /// <param name="config">Config from Page</param>
 /// <param name="pageStartInOne">If Page starts on index 1</param>
 /// <param name="defaultSort">Default value to sort ("ASC" or "DESC")</param>
 /// <typeparam name="TValue">Database type</typeparam>
 /// <typeparam name="TResult">Return type</typeparam>
 /// <returns></returns>
 public static IPage <TResult> ToPage <TValue, TResult>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     Func <IEnumerable <TValue>, IEnumerable <TResult> > mapperTo,
     IPageConfig config,
     bool pageStartInOne,
     string defaultSort)
     where TValue : class
     where TResult : class =>
 ToPage(
     listEntities,
     cacheRepository,
     mapperTo,
     config,
     pageStartInOne,
     defaultSort,
     "Id"
     );
        public static async Task <Expression <Func <TValue, object> > > CreateGenericOrderBy <TValue, TFilter>(
            this IPageConfig pageConfig,
            ICacheRepository cacheRepository,
            CancellationToken token)
        {
            var key = typeof(TFilter).Name;

            var dictionary = await cacheRepository.
                             GetDictionaryAttribute(key, pageConfig.Order, token).
                             ConfigureAwait(false);

            dictionary.TryGetValue(NameProperty, out var nameField);

            var order = (string)nameField.Value ?? pageConfig.Order;

            return(await GetGenericExpression <TValue>(order, cacheRepository, token).
                   ConfigureAwait(false));
        }
 /// <summary>
 /// Paginate entity TValue, no default values
 /// </summary>
 /// <param name="listEntities">IQueryable from entity TValue</param>
 /// <param name="config">Config from Page</param>
 /// <param name="pageStartInOne">If Page starts on index 1</param>
 /// <param name="defaultSort">Default value to sort ("ASC" or "DESC")</param>
 /// <param name="defaultOrder">Default value to order (Name property)</param>>
 /// <param name="defaultSize">Default value to size</param>
 /// <typeparam name="TValue"></typeparam>
 /// <returns></returns>
 public static IPage <TValue> ToPage <TValue>(
     this IQueryable <TValue> listEntities,
     ICacheRepository cacheRepository,
     IPageConfig config,
     bool pageStartInOne,
     string defaultSort,
     string defaultOrder,
     int defaultSize
     )
     where TValue : class =>
 new Page <TValue>(
     cacheRepository,
     listEntities,
     config,
     pageStartInOne,
     defaultSort,
     defaultOrder,
     defaultSize
     );
 protected AbstractPage(
     ICacheRepository cacheRepository,
     IQueryable <TValue> listEntities,
     IPageConfig config, bool pageStartInOne,
     string defaultSort, string defaultOrder,
     int defaultSize
     ) :
     base(
         cacheRepository,
         listEntities,
         null,
         config,
         pageStartInOne,
         defaultSort,
         defaultOrder,
         defaultSize
         )
 {
 }
Beispiel #23
0
        protected PageAttrAbstract(IQueryable <TIn> listEntities, IPageConfig config, ICacheRepository cache)
        {
            ThrowErrorIf.IsNullValue(config, nameof(config), typeof(PageAttrAbstract <,>).Name);

            ThrowErrorIf.IsNullValue(listEntities, nameof(listEntities), typeof(PageAttrAbstract <,>).Name);

            ThrowErrorIf.IsNullValue(cache, nameof(cache), typeof(PageAttrAbstract <,>).Name);

            Cache        = cache;
            PageConfig   = config;
            ListEntities = listEntities;
            Count        = listEntities.Count();

            Sort          = PageConfig.Sort.ToString();
            NumberPage    = PageConfig.Page;
            Order         = PageConfig.Order;
            Size          = PageConfig.Size;
            TotalElements = Count;

            TotalPage = TotalElements / Size;
        }
 protected AbstractPage(
     ICacheRepository cacheRepository,
     IQueryable <TValue> listEntities,
     Func <IEnumerable <TValue>, IEnumerable <TResult> > mapperTo,
     IPageConfig config,
     bool pageStartInOne,
     string defaultSort,
     string defaultOrder,
     int defaultSize
     )
 {
     _cacheRepository = cacheRepository;
     _mapperTo        = mapperTo;
     _count           = listEntities.Count();
     ValidateCtor(_count, config);
     _config         = config;
     _listEntities   = listEntities;
     _pageStatsInOne = pageStartInOne;
     _defaultOrder   = defaultOrder;
     _defaultSize    = defaultSize;
     _defaultSort    = defaultSort;
 }
 public virtual async Task <IPage <TValue> > GetPageAsync(
     IPageConfig config,
     bool EnableAsNoTracking) =>
 await Task.Run(() => GetAllQueryable(EnableAsNoTracking).ToPage <TValue>(_cacheService, config));
Beispiel #26
0
 public PageHelper(IOptions <PageConfig> options, IUrlHelper urlHelper, IMapper mapper)
 {
     _pageConfig = options.Value;
     _urlHelper  = urlHelper;
     _mapper     = mapper;
 }
Beispiel #27
0
        /// <summary>
        /// Adds services for PageHelper
        /// </summary>
        /// <param name="services">Service Collection</param>
        /// <param name="pageConfig">Default configuration for pagination</param>
        /// <returns>Service Collection</returns>
        public static IServiceCollection AddPaginationHelper(this IServiceCollection services, IPageConfig pageConfig)
        {
            services.AddSingleton(pageConfig);
            services.TryAddScoped <IPageHelper, PageHelper>();

            services.AddHttpContextAccessor();
            services.TryAddSingleton <IActionContextAccessor, ActionContextAccessor>();

            services
            .TryAddScoped(x => x
                          .GetRequiredService <IUrlHelperFactory>()
                          .GetUrlHelper(x.GetRequiredService <IActionContextAccessor>().ActionContext));

            return(services);
        }