コード例 #1
0
        public async Task <BrokerPackageViewDomain> GetBrokerPackageViewListAsync(
            BrokerPackageViewQueryParameters queryParameters)
        {
            var filteredPackageQuery = _dbContext.CarePackages
                                       .FilterBrokerViewPackages(queryParameters.ServiceUserId, queryParameters.ServiceUserName,
                                                                 queryParameters.Status, queryParameters.BrokerId, queryParameters.FromDate, queryParameters.ToDate);

            var packages = await filteredPackageQuery
                           .AsNoTracking()
                           .Select(cp => new BrokerPackageItemDomain
            {
                PackageId       = cp.Id,
                ServiceUserId   = cp.ServiceUserId,
                ServiceUserName =
                    $"{cp.ServiceUser.FirstName} {cp.ServiceUser.MiddleName ?? string.Empty} {cp.ServiceUser.LastName}",
                DateOfBirth   = cp.ServiceUser.DateOfBirth,
                Address       = cp.ServiceUser.AddressLine1,
                HackneyId     = cp.ServiceUser.HackneyId.ToString(),
                PackageType   = cp.PackageType.GetDisplayName(),
                PackageStatus = cp.Status.GetDisplayName(),
                BrokerName    = cp.Broker.Name,
                DateAssigned  = cp.DateCreated
            })
                           .ToListAsync();

            var preferences = FilterPreferences.BrokerListStatus();

            packages = packages
                       .OrderBy(x => preferences.IndexOf(x.PackageStatus)).ThenBy(x => x.DateAssigned)
                       .ToList();

            packages = packages
                       .Skip((queryParameters.PageNumber - 1) * queryParameters.PageSize)
                       .Take(queryParameters.PageSize).ToList();

            var packageCount = await filteredPackageQuery
                               .CountAsync();

            var pagedPackages = PagedList <BrokerPackageItemDomain> .ToPagedList(packages, packageCount, queryParameters.PageNumber, queryParameters.PageSize);

            var statusCount = await filteredPackageQuery
                              .Select(p => new { p.Id, p.Status })
                              .GroupBy(p => p.Status)
                              .Select(p => new CarePackageByStatusDomain
            {
                StatusName = p.Key.GetDisplayName(),
                Number     = p.Count()
            })
                              .ToListAsync();

            return(new BrokerPackageViewDomain
            {
                Packages = pagedPackages,
                StatusCount = statusCount.ToDictionary(statusGroup => statusGroup.StatusName, statusGroup => statusGroup.Number),
                PagingMetaData = pagedPackages.PagingMetaData
            });
        }
コード例 #2
0
        public GetCarePackageUseCaseTest()
        {
            _fixture          = new Fixture();
            _brokerViewDomain = _fixture.Build <BrokerPackageViewDomain>()
                                .Create();

            _queryFilter = new BrokerPackageViewQueryParameters
            {
                PageNumber = 1,
                PageSize   = 10
            };

            _gatewayMock = new Mock <ICarePackageGateway>();
            _gatewayMock
            .Setup(m => m.GetBrokerPackageViewListAsync(_queryFilter))
            .ReturnsAsync(_brokerViewDomain);

            _useCase = new GetCarePackageUseCase(
                _gatewayMock.Object);
        }
コード例 #3
0
        public async Task <ActionResult <BrokerPackageViewResponse> > GetBrokerPackageView([FromQuery] BrokerPackageViewQueryParameters queryParameters)
        {
            var res = await _getCarePackageUseCase.GetBrokerPackageViewListAsync(queryParameters);

            return(Ok(res));
        }
コード例 #4
0
        public async Task <BrokerPackageViewResponse> GetBrokerPackageViewListAsync(BrokerPackageViewQueryParameters queryParameters)
        {
            var result = await _carePackageGateway.GetBrokerPackageViewListAsync(queryParameters);

            return(result.ToResponse());
        }