Example #1
0
        public virtual async Task <IEnumerable <TDto> > GetAllAsync(
            CancellationToken cancellationToken,
            //Expression<Func<IQueryable<TDto>, IOrderedQueryable<TDto>>> orderBy = null,
            string orderBy    = null,
            int?pageNo        = null,
            int?pageSize      = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestException(Messages.OrderByInvalid);
            }

            var orderByConverted = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);
            //var orderByConverted = MapOrderBy<TDto, TEntity>(orderBy);

            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            var entityList = await Repository.GetAllAsync(cancellationToken, orderByConverted, pageNo, pageSize, GetFullGraph || getFullGraph, includesConverted).ConfigureAwait(false);

            IEnumerable <TDto> dtoList = entityList.ToList().Select(Mapper.Map <TEntity, TDto>);

            return(dtoList);
        }
Example #2
0
        public virtual IEnumerable <TDto> GetAll(
            string orderBy    = null,
            int?pageNo        = null,
            int?pageSize      = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestException(Messages.OrderByInvalid);
            }

            var orderByConverted = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);

            //var orderByConverted = MapOrderBy<TDto, TEntity>(orderBy);
            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            var entityList = Repository.GetAll(orderByConverted, pageNo, pageSize, GetFullGraph || getFullGraph, includesConverted);

            IEnumerable <TDto> dtoList = entityList.ToList().Select(Mapper.Map <TEntity, TDto>);

            return(dtoList);
        }
Example #3
0
        public virtual async Task <TDto> GetFirstAsync(
            CancellationToken cancellationToken,
            Expression <Func <TDto, bool> > filter = null,
            string orderBy    = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            var filterConverted = MapWhereClause <TDto, TEntity>(filter);

            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestException(Messages.OrderByInvalid);
            }

            var orderByConverted = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);

            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            var bo = await Repository.GetFirstAsync(cancellationToken, filterConverted, orderByConverted, GetFullGraph || getFullGraph, includesConverted).ConfigureAwait(false);

            return(Mapper.Map <TDto>(bo));
        }
        public virtual TDto GetFirst(
            Expression <Func <TDto, bool> > filter = null,
            string orderBy    = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            AuthorizeResourceOperationAsync(ResourceCollectionsCore.CRUD.Operations.Read, ResourceCollectionsCore.CRUD.Operations.ReadOwner).Wait();

            var filterConverted = MapWhereClause <TDto, TEntity>(filter);

            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestError(Messages.OrderByInvalid);
            }

            var orderByConverted = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);

            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            var bo = Repository.GetFirst(filterConverted, orderByConverted, GetFullGraph || getFullGraph, includesConverted);

            AuthorizeResourceOperationAsync(bo, ResourceCollectionsCore.CRUD.Operations.Read, ResourceCollectionsCore.CRUD.Operations.ReadOwner).Wait();

            return(Mapper.Map <TDto>(bo));
        }
        public virtual async Task <PagedList <TDto> > SearchAsync(
            CancellationToken cancellationToken,
            string ownedBy = null,
            string search  = "",
            Expression <Func <TDto, bool> > filter = null,
            string orderBy    = null,
            int?pageNo        = null,
            int?pageSize      = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            await AuthorizeResourceOperationAsync(ResourceCollectionsCore.CRUD.Operations.Read, ResourceCollectionsCore.CRUD.Operations.ReadOwner);

            var filterConverted = MapWhereClause <TDto, TEntity>(filter);

            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestError(Messages.OrderByInvalid);
            }

            var orderByConverted = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);

            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            int?skip = null;

            if (pageNo.HasValue && pageSize.HasValue)
            {
                skip = (pageNo.Value - 1) * pageSize.Value;
            }

            filterConverted = Repository.And(Repository.And(filterConverted, Repository.PredicateEntityByOwner(ownedBy)), Repository.PredicateEntityByStringContains(search));
            var entityList = await Repository.SearchAsync(cancellationToken, filterConverted, orderByConverted, skip, pageSize, GetFullGraph || getFullGraph, includesConverted).ConfigureAwait(false);

            var entities = entityList.ToList();

            foreach (var entity in entities)
            {
                await AuthorizeResourceOperationAsync(entity, ResourceCollectionsCore.CRUD.Operations.Read, ResourceCollectionsCore.CRUD.Operations.ReadOwner);
            }

            var dtoList = new PagedList <TDto>(entities.Select(Mapper.Map <TEntity, TDto>).ToList(), entityList.TotalCount, pageNo ?? 1, pageSize ?? entityList.TotalCount);

            return(dtoList);
        }
        public virtual IEnumerable <TDto> Get(
            Expression <Func <TDto, bool> > filter = null,
            string orderBy    = null,
            int?pageNo        = null,
            int?pageSize      = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            AuthorizeResourceOperationAsync(ResourceCollectionsCore.CRUD.Operations.Read, ResourceCollectionsCore.CRUD.Operations.ReadOwner).Wait();

            var filterConverted = MapWhereClause <TDto, TEntity>(filter);

            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestError(Messages.OrderByInvalid);
            }

            var orderByConverted  = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);
            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            int?skip = null;

            if (pageNo.HasValue && pageSize.HasValue)
            {
                skip = (pageNo.Value - 1) * pageSize.Value;
            }

            var entityList = Repository.Get(filterConverted, orderByConverted, skip, pageSize, GetFullGraph || getFullGraph, includesConverted);

            var entities = entityList.ToList();

            foreach (var entity in entities)
            {
                AuthorizeResourceOperationAsync(entity, ResourceCollectionsCore.CRUD.Operations.Read, ResourceCollectionsCore.CRUD.Operations.ReadOwner).Wait();
            }

            IEnumerable <TDto> dtoList = entities.Select(Mapper.Map <TEntity, TDto>);

            return(dtoList);
        }
Example #7
0
        public virtual PagedList <TDto> Search(
            string ownedBy = null,
            string search  = "",
            Expression <Func <TDto, bool> > filter = null,
            string orderBy    = null,
            int?pageNo        = null,
            int?pageSize      = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            var filterConverted = MapWhereClause <TDto, TEntity>(filter);

            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestException(Messages.OrderByInvalid);
            }

            var orderByConverted = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);

            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);
            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            int?skip = null;

            if (pageNo.HasValue && pageSize.HasValue)
            {
                skip = (pageNo.Value - 1) * pageSize.Value;
            }

            filterConverted = Repository.And(Repository.And(filterConverted, Repository.PredicateEntityByOwner(ownedBy)), Repository.PredicateEntityByStringContains(search));
            var entityList = Repository.Search(filterConverted, orderByConverted, skip, pageSize, GetFullGraph || getFullGraph, includesConverted);

            var entities = entityList.ToList();

            var dtoList = new PagedList <TDto>(entities.Select(Mapper.Map <TEntity, TDto>).ToList(), entityList.TotalCount, pageNo ?? 1, pageSize ?? entityList.TotalCount);

            return(dtoList);
        }
Example #8
0
        public virtual async Task <IEnumerable <TDto> > GetAsync(
            CancellationToken cancellationToken,
            Expression <Func <TDto, bool> > filter = null,
            string orderBy    = null,
            int?pageNo        = null,
            int?pageSize      = null,
            bool getFullGraph = false,
            params Expression <Func <TDto, Object> >[] includeProperties)
        {
            var filterConverted = MapWhereClause <TDto, TEntity>(filter);

            if (!OrderByMapper.ValidOrderByFor <TDto, TEntity>(orderBy))
            {
                throw new BadRequestException(Messages.OrderByInvalid);
            }

            var orderByConverted  = OrderByMapper.GetOrderByDelegate <TDto, TEntity>(orderBy);
            var includesConverted = MapIncludes <TDto, TEntity>(includeProperties);

            var list = includesConverted.ToList();

            AddIncludes(list);
            includesConverted = list.ToArray();

            int?skip = null;

            if (pageNo.HasValue && pageSize.HasValue)
            {
                skip = (pageNo.Value - 1) * pageSize.Value;
            }

            var entityList = await Repository.GetAsync(cancellationToken, filterConverted, orderByConverted, skip, pageSize, GetFullGraph || getFullGraph, includesConverted).ConfigureAwait(false);

            var entities = entityList.ToList();

            IEnumerable <TDto> dtoList = entityList.ToList().Select(Mapper.Map <TEntity, TDto>);

            return(dtoList);
        }