コード例 #1
0
        public async Task <ResultObjectInfo <LogItemDto> > GetLogAsync(int logNumber)
        {
            var log = await GetAsync(x => x.Number == logNumber && x.AppName == _options.AppName);

            if (log == null)
            {
                return(NotFound <LogItemDto>(LogNotFound));
            }

            var mapper = AutoMapperDomainUtils.GetMapper(config => config.CreateMap <LogItem, LogItemDto>());

            return(Ok(mapper.Map <LogItemDto>(log)));
        }
コード例 #2
0
        public virtual PagingQueryable <TCast> GetPage <TCast>(RepositoryPagingModel <TCast> filter, Expression <Func <T, bool> > checkPermission, List <Expression <Func <T, bool> > > @where, Action <IMapperConfigurationExpression> configure, List <Expression <Func <TCast, bool> > > postWhere = null) where TCast : class
        {
            var page = new Page(filter.PageNumber, filter.PageSize);

            var queryable = Dbset;

            if (checkPermission != null)
            {
                queryable = queryable.Where(checkPermission);
            }

            foreach (var expression in where)
            {
                queryable = queryable.Where(expression);
            }

            var configurationProvider = AutoMapperDomainUtils.GetConfigurationProvider(config =>
            {
                configure.Invoke(config);
                var mappingExpression = ((IProfileConfiguration)config).TypeMapConfigs.FirstOrDefault(x => x is IMappingExpression <T, TCast>) as IMappingExpression <T, TCast>;
                mappingExpression?.LoadProperties(filter, DataContext);
            });
            var castQuery = queryable.ProjectTo <TCast>(configurationProvider).AsExpandable().WithTranslations();

            if (postWhere != null)
            {
                foreach (var expression in postWhere)
                {
                    castQuery = castQuery.Where(expression);
                }
            }

            if (filter.Filters?.Any() ?? false)
            {
                castQuery = castQuery.Where(QueryableUtils.FiltersToLambda <TCast>(filter.Filters));
            }

            var orderProperties = filter.OrderProperty?.Split(new[] { ',', ' ', '/', '\\' }, StringSplitOptions.RemoveEmptyEntries).ToList() ?? new List <string>();

            IOrderedQueryable <TCast> orderedQuery;

            if (filter.Distinct.IsNullOrEmpty())
            {
                orderProperties.AddRange(_dataContext.GetKeyNames <T>());
                orderProperties = orderProperties.Distinct(new GenericCompare <string>(x => x.ToLowerInvariant())).ToList();

                if (orderProperties.Any())
                {
                    orderedQuery = filter.IsDesc ? castQuery.OrderByDescendingWithNullLowPriority(orderProperties.First()) : castQuery.OrderByWithNullLowPriority(orderProperties.First());
                    orderProperties.RemoveAt(0);
                }
                else
                {
                    orderedQuery = filter.IsDesc ? castQuery.OrderByDescendingWithNullLowPriority() : castQuery.OrderByWithNullLowPriority();
                }
                if (orderProperties.Any())
                {
                    orderedQuery = orderProperties.Aggregate(orderedQuery, (current, property) => filter.IsDesc ? current.ThenByDescendingWithNullLowPriority(property) : current.ThenByWithNullLowPriority(property));
                }
                else
                {
                    orderedQuery = filter.IsDesc ? orderedQuery.ThenByDescendingWithNullLowPriority() : orderedQuery.ThenByWithNullLowPriority();
                }
            }
            else
            {
                castQuery    = castQuery.DistinctByField(filter.Distinct).AsExpandable();
                orderedQuery = filter.IsDesc ? castQuery.OrderByDescendingWithNullLowPriority(filter.Distinct) : castQuery.OrderByWithNullLowPriority(filter.Distinct);
            }

            return(new PagingQueryable <TCast>(orderedQuery, page));
        }