Exemplo n.º 1
0
        private async Task LookupCharityCommissionDetails(ApplyGatewayDetails applyGatewayDetails, string charityNumberFromUkrlp)
        {
            if (int.TryParse(charityNumberFromUkrlp, out var charityNumber))
            {
                var charityDetails = await _charityCommissionClient.GetCharity(charityNumber);

                if (charityDetails == null)
                {
                    var message = $"Unable to retrieve Charity Commission details for charity number {charityNumber}";
                    _logger.LogError(message);
                    throw new ServiceUnavailableException(message);
                }
                applyGatewayDetails.CharityCommissionDetails = Mapper.Map <CharityCommissionSummary>(charityDetails);
            }
        }
Exemplo n.º 2
0
        public async Task <Charity> GetCharityDetails(int charityNumber)
        {
            _logger.LogInformation($"GetCharityDetails({charityNumber})");

            Charity charity = null;

            try
            {
                charity = await _charityCommissionApiClient.GetCharity(charityNumber);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error from Charity Commission. Message: {ex.Message}");
            }

            return(charity);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CharityDetails(int charityNumber)
        {
            try
            {
                var charityDetails =
                    await _retryPolicy.ExecuteAsync(context => _apiClient.GetCharity(charityNumber), new Context());

                if (charityDetails == null)
                {
                    return(NotFound());
                }

                return(Ok(charityDetails));
            }
            catch (ServiceUnavailableException)
            {
                return(StatusCode(StatusCodes.Status503ServiceUnavailable));
            }
        }