public async Task <IEnumerable <ApiSpecificationSummary> > GetSpecificationsSelectedForFundingByPeriod(string fundingPeriodId)
        {
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));

            ApiResponse <IEnumerable <ApiSpecificationSummary> > specificationSummaryResponse =
                await _resiliencePolicy.ExecuteAsync(() => _specifications.GetSpecificationsSelectedForFundingByPeriod(fundingPeriodId));

            if (specificationSummaryResponse.StatusCode.IsSuccess())
            {
                return(specificationSummaryResponse.Content);
            }

            return(null);
        }
        public async Task <IActionResult> GetSpecificationsForFundingByPeriod(string fundingPeriodId)
        {
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));

            ApiResponse <IEnumerable <SpecificationSummary> > apiResponse = await _specificationsApiClient.GetSpecificationsSelectedForFundingByPeriod(fundingPeriodId);

            if (apiResponse.StatusCode == HttpStatusCode.OK)
            {
                return(Ok(apiResponse.Content.OrderBy(c => c.Name)));
            }

            if (apiResponse.StatusCode == HttpStatusCode.NotFound)
            {
                return(NoContent());
            }

            if (apiResponse.StatusCode == HttpStatusCode.BadRequest)
            {
                return(new BadRequestResult());
            }

            return(new StatusCodeResult(500));
        }
예제 #3
0
 private void GivenTheSpecificationSummariesInTheFundingPeriod(params SpecificationSummary[] specificationSummaries)
 {
     _specificationsApiClient
     .GetSpecificationsSelectedForFundingByPeriod(_fundingPeriodId)
     .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specificationSummaries));
 }
        public async Task DeselectSpecificationForFunding(string fundingStreamId, string fundingPeriodId)
        {
            _logger.Information($"Deselecting specification for funding for {fundingStreamId} {fundingPeriodId}");

            ApiResponse <IEnumerable <SpecificationSummary> > response = await _specsApiPolicy.ExecuteAsync(() =>
                                                                                                            _specificationsApiClient.GetSpecificationsSelectedForFundingByPeriod(fundingPeriodId));

            SpecificationSummary specificationSummary = response?.Content?
                                                        .FirstOrDefault(_ => _.FundingStreams?.Any(fs => fs.Id == fundingStreamId) == true);

            if (specificationSummary == null)
            {
                throw new ArgumentOutOfRangeException(nameof(fundingStreamId), $"Did not locate a specification selected for funding for {fundingStreamId} {fundingPeriodId}");
            }

            HttpStatusCode statusCode = await _specsApiPolicy.ExecuteAsync(() =>
                                                                           _specificationsApiClient.DeselectSpecificationForFunding(specificationSummary.Id));

            if (!statusCode.IsSuccess())
            {
                throw new InvalidOperationException($"Unable to deselect specification for funding for {fundingStreamId} {fundingPeriodId}");
            }
        }