Пример #1
0
        public async Task <PharmanetCollegeRecord> GetCollegeRecordAsync(Certification certification)
        {
            if (certification == null)
            {
                throw new ArgumentNullException(nameof(certification));
            }

            var requestParams = new CollegeRecordRequestParams(certification);

            HttpResponseMessage response = null;

            try
            {
                response = await _client.PostAsync(PrimeConstants.PHARMANET_API_URL, requestParams.ToRequestContent());
            }
            catch (Exception ex)
            {
                await LogError(requestParams, response, ex);

                throw new PharmanetCollegeApiException("Error occurred when calling Pharmanet API. Try again later.", ex);
            }

            if (!response.IsSuccessStatusCode)
            {
                await LogError(requestParams, response);

                throw new PharmanetCollegeApiException($"Error code {response.StatusCode} was returned when calling Pharmanet API.");
            }

            var content = await response.Content.ReadAsAsync <List <PharmanetCollegeRecord> >();

            var practicionerRecord = content.SingleOrDefault();

            // If we get a record back, it should have the same transaction UUID as our request.
            if (practicionerRecord != null && practicionerRecord.applicationUUID != requestParams.applicationUUID)
            {
                throw new PharmanetCollegeApiException($"Expected matching applicationUUIDs between request data and response data. Request was \"{requestParams.applicationUUID}\", response was \"{practicionerRecord.applicationUUID}\".");
            }

            return(practicionerRecord);
        }