public async Task <IActionResult> PreviewProfilingChange(ProfilePreviewRequest request) { Guard.ArgumentNotNull(request, nameof(request)); ReProfileRequest reProfileRequest = await _reProfilingRequestBuilder.BuildReProfileRequest(request.SpecificationId, request.FundingStreamId, request.FundingPeriodId, request.ProviderId, request.FundingLineCode, request.ProfilePatternKey, request.ConfigurationType); ApiResponse <ReProfileResponse> reProfilingApiResponse = await _profilingResilience.ExecuteAsync(() => _profiling.ReProfile(reProfileRequest)); ReProfileResponse reProfileResponse = reProfilingApiResponse?.Content; if (reProfileResponse == null) { throw new InvalidOperationException( $"Did not received a valid re-profiling response for profile pattern preview request {request}"); } ExistingProfilePeriod[] existingProfilePeriods = reProfileRequest.ExistingPeriods.ToArray(); int isPaidTo = GetIsPaidTo(existingProfilePeriods); ProfileTotal[] profileTotals = BuildProfileTotals(reProfileResponse, existingProfilePeriods, isPaidTo); await AddFundingDatesToProfileTotals(request, profileTotals); return(new OkObjectResult(profileTotals)); }
private async Task ReProfileFundingLine(PublishedProviderVersion newPublishedProviderVersion, ProfilePatternKey profilePatternKey, string fundingLineCode, FundingLine fundingLine) { ReProfileRequest reProfileRequest = await _profilingRequestBuilder.BuildReProfileRequest(newPublishedProviderVersion.SpecificationId, newPublishedProviderVersion.FundingStreamId, newPublishedProviderVersion.FundingPeriodId, newPublishedProviderVersion.ProviderId, fundingLineCode, profilePatternKey.Key, ProfileConfigurationType.Custom, fundingLine.Value); ReProfileResponse reProfileResponse = (await _profilingPolicy.ExecuteAsync(() => _profiling.ReProfile(reProfileRequest)))?.Content; if (reProfileResponse == null) { string error = $"Unable to re-profile funding line {fundingLineCode} on specification {newPublishedProviderVersion.SpecificationId} with profile pattern {profilePatternKey.Key}"; _logger.Error(error); throw new InvalidOperationException(error); } fundingLine.DistributionPeriods = _reProfilingResponseMapper.MapReProfileResponseIntoDistributionPeriods(reProfileResponse); newPublishedProviderVersion.RemoveCarryOver(fundingLineCode); if (reProfileResponse.CarryOverAmount > 0) { newPublishedProviderVersion.AddCarryOver(fundingLineCode, ProfilingCarryOverType.CustomProfile, reProfileResponse.CarryOverAmount); } }