Beispiel #1
0
        private Expression <Func <Workflow, bool> > GetWhereClause(
            WorkflowSearchPagingParameters pagingParameters
            )
        {
            var predicate = PredicateBuilder.True <Workflow>();

            if (pagingParameters.HasType)
            {
                predicate = predicate
                            .And(w => w.Type.ToLowerInvariant()
                                 .StartsWith(pagingParameters.Type.ToLowerInvariant()));
            }
            if (pagingParameters.HasCorrelationId)
            {
                predicate = predicate
                            .And(w => w.CorrelationId == pagingParameters.CorrelationId);
            }
            if (pagingParameters.HasAssignee)
            {
                predicate = predicate
                            .And(w => w.Assignee.ToLowerInvariant()
                                 .StartsWith(pagingParameters.Assignee.ToLowerInvariant()));
            }

            return(predicate);
        }
        private static List <Expression <Func <Workflow, bool> > > GetCriterias(
            WorkflowSearchPagingParameters pagingParameters
            )
        {
            List <Expression <Func <Workflow, bool> > > criterias
                = new List <Expression <Func <Workflow, bool> > >();

            if (pagingParameters.HasType)
            {
                criterias.Add(w => w.Type.ToLower()
                              .StartsWith(pagingParameters.Type.ToLower()));
            }

            if (pagingParameters.HasCorrelationId)
            {
                criterias.Add(
                    w => w.CorrelationId == pagingParameters.CorrelationId);
            }

            if (pagingParameters.HasAssignee)
            {
                criterias.Add(w => w.Assignee.ToLower()
                              .StartsWith(pagingParameters.Assignee.ToLower()));
            }

            return(criterias);
        }
Beispiel #3
0
        public async Task <PaginatedList <WorkflowViewModel> > GetWorkflowsAsync(
            WorkflowSearchPagingParameters pagingParameters
            )
        {
            var count = await this.repository.CountAsync(new WorkflowCount());

            IReadOnlyList <Workflow> instances = null;

            if (pagingParameters.HasValues)
            {
                instances = await this.repository
                            .ListAsync(new WorkflowInstancesFilterAndOrderedPaginated(
                                           pagingParameters
                                           ));
            }
            else
            {
                instances = await this.repository
                            .ListAsync(new WorkflowInstancesOrderedPaginated(
                                           pagingParameters.SkipCount,
                                           pagingParameters.PageSize
                                           ));
            }

            var items = instances.Select(i => this.ToWorkflowViewModel(i));

            return(new PaginatedList <WorkflowViewModel>(
                       items,
                       count,
                       pagingParameters.PageIndex,
                       pagingParameters.PageSize
                       ));
        }
        public async Task <ActionResult <PaginatedList <WorkflowViewModel> > > GetWorkflows(
            [FromQuery] WorkflowSearchPagingParameters pagingParameters
            )
        {
            var result = await this.service.GetWorkflowsAsync(pagingParameters);

            this.AddXPagination(pagingParameters, result);

            return(Ok(result));
        }
Beispiel #5
0
        public async Task <PaginatedList <WorkflowViewModel> > GetWorkflowsAsync(
            WorkflowSearchPagingParameters parameters
            )
        {
            var result = await this.service.GetWorkflowsAsync(parameters);

            return(new PaginatedList <WorkflowViewModel>(
                       result.Select(x => ToViewModel(x)),
                       result.AllItemsCount,
                       parameters.PageIndex,
                       parameters.PageSize
                       ));
        }
        public WorkflowInstancesFilterAndOrderedPaginated(
            WorkflowSearchPagingParameters pagingParameters
            ) : base()
        {
            var criterias = GetCriterias(pagingParameters);

            foreach (var criteria in criterias)
            {
                this.AddCriteria(criteria);
            }

            this.ApplyOrderByDescending(w => w.Id);
            this.ApplyPaging(pagingParameters.SkipCount, pagingParameters.PageSize);
            this.ApplyNoTracking();
        }
Beispiel #7
0
        public async Task <PaginatedList <WorkflowViewModel> > GetWorkflowsAsync(
            WorkflowSearchPagingParameters pagingParameters
            )
        {
            var count = _context.Workflows.Count();

            List <Workflow> instances = null;

            if (pagingParameters.HasValues)
            {
                // TODO: to be improved!!!
                // Specification Pattern
                // see: https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-implemenation-entity-framework-core#implementing-the-specification-pattern
                instances = await _context.Workflows
                            .Where(this.GetWhereClause(pagingParameters))
                            .OrderByDescending(w => w.Id)
                            .Skip(pagingParameters.SkipCount)
                            .Take(pagingParameters.PageSize)
                            .AsNoTracking()
                            .ToListAsync();
            }
            else
            {
                instances = await _context.Workflows
                            .OrderByDescending(w => w.Id)
                            .Skip(pagingParameters.SkipCount)
                            .Take(pagingParameters.PageSize)
                            .AsNoTracking()
                            .ToListAsync();
            }

            var items = instances.Select(i => ToWorkflowViewModel(i));

            return(new PaginatedList <WorkflowViewModel>(
                       items,
                       count,
                       pagingParameters.PageIndex,
                       pagingParameters.PageSize
                       ));
        }