示例#1
0
        public OedSearchResultsModel Execute(OedSearchResultsModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (model.Query == null)
            {
                throw new ArgumentNullException(nameof(model.Query));
            }

            return(ExecuteAsync(model).Result);
        }
示例#2
0
        public async Task <OedSearchResultsModel> ExecuteAsync(OedSearchResultsModel model)
        {
            if (model.Query == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var client = _clientFactory.CreateClient();

            string wordId   = model.Query.ToLower();
            var    response = await client.GetAsync($"search/{Language}?q={wordId}");

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException(
                          $"Error calling service at '{client.BaseAddress}', status code is '{response.StatusCode}', content is '{response.Content.ReadAsStringAsync().Result}'");
            }
            var json   = response.Content.ReadAsStringAsync().Result;
            var result = JsonConvert.DeserializeObject <OedSearchResults>(json);

            return(model);
        }