Ejemplo n.º 1
0
 protected EfCoreControllerBase(
     IEfQueryRepository <TEntity> queryRepository,
     IEfRepositoryAsync <TEntity> mutateRepository)
 {
     QueryRepository  = queryRepository;
     MutateRepository = mutateRepository;
 }
 public static async Task <PaginatedItem <TResponse> > QueryAsync <TDbContext, TEntity, TResponse>(
     this IEfRepositoryAsync <TDbContext, TEntity> repo,
     Criterion criterion,
     Expression <Func <TEntity, TResponse> > selector,
     params Expression <Func <TEntity, object> >[] includeProperties)
     where TDbContext : DbContext
     where TEntity : EntityBase
 {
     return(await GetDataAsync(repo, criterion, selector, null, includeProperties));
 }
Ejemplo n.º 3
0
 public CartService(
     IEfQueryRepository <Domain.Cart> queryRepository,
     IEfRepositoryAsync <Domain.Cart> mutateRepository,
     IEfRepositoryAsync <CartItem> cartItemMutateRepository,
     ICatalogService catalogService)
 {
     _catalogService           = catalogService;
     _queryRepository          = queryRepository;
     _mutateRepository         = mutateRepository;
     _cartItemMutateRepository = cartItemMutateRepository;
 }
        public PostController(IUnitOfWorkAsync unitOfWork,
                              IOptions <PagingOption> pagingOption,
                              IHubContext <PostMessageHub> postMessageHubContext)
        {
            _postRepo        = unitOfWork.Repository <Models.Post>() as IEfRepositoryAsync <Models.Post>;
            _postCommentRepo = unitOfWork.Repository <Models.PostComment>() as IEfRepositoryAsync <Models.PostComment>;
            _clapRepo        = unitOfWork.Repository <Models.Clap>() as IEfRepositoryAsync <Models.Clap>;
            _pagingOption    = pagingOption;

            _postMessageHubContext = postMessageHubContext;
        }
Ejemplo n.º 5
0
 public TaskController(
     IUnitOfWorkAsync unitOfWork,
     IEfQueryRepository <Domain.Task> taskQuery,
     IGetTasksService getTasksService,
     IOptions <PaginationOption> paginationOption)
 {
     _taskRepository   = unitOfWork.Repository <Domain.Task>() as IEfRepositoryAsync <Domain.Task>;
     _taskQuery        = taskQuery;
     _getTasksService  = getTasksService;
     _paginationOption = paginationOption;
 }
        private static async Task <PaginatedItem <TResponse> > GetDataAsync <TDbContext, TEntity, TResponse>(
            IEfRepositoryAsync <TDbContext, TEntity> repo,
            Criterion criterion,
            Expression <Func <TEntity, TResponse> > selector,
            Expression <Func <TEntity, bool> > filter = null,
            params Expression <Func <TEntity, object> >[] includeProperties)
            where TDbContext : DbContext
            where TEntity : EntityBase
        {
            if (criterion.PageSize < 1 || criterion.PageSize > criterion.DefaultPagingOption.PageSize)
            {
                criterion.SetPageSize(criterion.DefaultPagingOption.PageSize);
            }

            var queryable   = repo.DbContext.Set <TEntity>() as IQueryable <TEntity>;
            var totalRecord = await queryable.CountAsync();

            var totalPages = (int)Math.Ceiling((double)totalRecord / criterion.PageSize);

            if (includeProperties != null && includeProperties.Count() > 0)
            {
                queryable = includeProperties.Aggregate(
                    queryable,
                    (current, include) => current.Include(include));
            }

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

            if (!string.IsNullOrWhiteSpace(criterion.SortBy))
            {
                var isDesc = string.Equals(criterion.SortOrder, "desc", StringComparison.OrdinalIgnoreCase) ? true : false;
                queryable = queryable.OrderByPropertyName(criterion.SortBy, isDesc);
            }

            if (criterion.CurrentPage > totalPages)
            {
                criterion.SetCurrentPage(totalPages);
            }

            var results = await queryable
                          .Skip(criterion.CurrentPage *criterion.PageSize)
                          .Take(criterion.PageSize)
                          .AsNoTracking()
                          .Select(selector)
                          .ToListAsync();

            return(new PaginatedItem <TResponse>(totalRecord, totalPages, results));
        }
        public static async Task <TEntity> FindOneAsync <TDbContext, TEntity>(
            this IEfRepositoryAsync <TDbContext, TEntity> repo,
            Expression <Func <TEntity, bool> > filter,
            params Expression <Func <TEntity, object> >[] includeProperties)
            where TDbContext : DbContext
            where TEntity : EntityBase
        {
            var dbSet = repo.DbContext.Set <TEntity>() as IQueryable <TEntity>;

            foreach (var includeProperty in includeProperties)
            {
                dbSet = dbSet.Include(includeProperty);
            }

            return(await dbSet.FirstOrDefaultAsync(filter));
        }
Ejemplo n.º 8
0
 protected CrudControllerBase(
     IEfQueryRepository <TEntity> queryRepository,
     IEfRepositoryAsync <TEntity> mutateRepository)
     : base(queryRepository, mutateRepository)
 {
 }
Ejemplo n.º 9
0
 public CustomCollectionController(IUnitOfWorkAsync unitOfWork)
 {
     _unitOfWork         = unitOfWork;
     _morphismRepository = _unitOfWork.Repository <Morphism>() as IEfRepositoryAsync <Morphism>;
 }