Пример #1
0
        public RestResult <T> Post <T, TContent>(string url, TContent body, Dictionary <string, string> headers = null)
        {
            RestResult <T> result;
            var            httpContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");

            if (headers == null)
            {
                using (var httpClient = _httpClientServiceFactory.Create(url, _authenticationHeader))
                {
                    var response = httpClient.PostAsync(string.Empty, httpContent).Result;
                    result = GetResult <T>(response);
                }
            }
            else
            {
                using (var httpClient = _httpClientServiceFactory.Create(url, headers))
                {
                    var response = httpClient.PostAsync(string.Empty, httpContent).Result;
                    result = GetResult <T>(response);
                }
            }



            return(result);
        }
Пример #2
0
        /// <summary>
        /// Get a list of Local Authrities from the FHRS API.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Authority> GetLocalAuthorities()
        {
            using (IHttpClientService httpClientService = _httpClientServiceFactory.Create(ConfigurationOptions.Value.ServiceAddress, ConfigurationOptions.Value.AuthorityEndpoint, GetApiHeaders()))
            {
                var httpResponse = httpClientService.GetSingleAsync <AuthorityResponse>().Result;

                if (!httpResponse.IsSuccessful)
                {
                    throw new InvalidOperationException(httpResponse.ErrorMessage);
                }

                return(httpResponse.ResponseContent.Authorities);
            }
        }
        /// <summary>
        /// Get a list of establishments by authority Id.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Establishment> GetEstablishments(int id)
        {
            var parameters = new List <KeyValuePair <string, string> >();

            parameters.Add(new KeyValuePair <string, string>("localauthorityid", id.ToString()));
            parameters.Add(new KeyValuePair <string, string>("pagesize", "0"));


            using (IHttpClientService httpClientService = _httpClientServiceFactory.Create(ConfigurationOptions.Value.ServiceAddress, ConfigurationOptions.Value.EstablishmentEndpoint, GetApiHeaders()))
            {
                var httpResponse = httpClientService.GetAsync <EstablishmentResponse>(parameters).Result;

                if (!httpResponse.IsSuccessful)
                {
                    throw new InvalidOperationException(httpResponse.ErrorMessage);
                }

                return(httpResponse.ResponseContent.Establishments);
            }
        }