internal static string ToJson(this IGetVenueByVenueIdCriteria extendee) { GetVenueByVenueIdJson json = new GetVenueByVenueIdJson { venueId = extendee.venueId }; var result = JsonConvert.SerializeObject(json); return(result); }
public async Task <IResult <IVenue> > GetVenueByVenueIdAsync(IGetVenueByVenueIdCriteria criteria) { Throw.IfNull(criteria, nameof(criteria)); _logger.LogMethodEnter(); try { _logger.LogInformationObject("Get Venue By VenueId criteria.", criteria); _logger.LogInformationObject("Get Venue By VenueId URI", _getVenueByVenueIdUri); var content = new StringContent(criteria.ToJson(), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(_getVenueByVenueIdUri, content); _logger.LogHttpResponseMessage("Get Venue By VenueId service http response", response); if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); _logger.LogInformationObject("Get Venue By VenueId service json response", json); var settings = new JsonSerializerSettings { ContractResolver = new VenueSearchResultContractResolver() }; var venue = JsonConvert.DeserializeObject <Venue>(json, settings); return(Result.Ok <IVenue>(venue)); } else { return(Result.Fail <IVenue>("Get Venue By VenueId service unsuccessful http response")); } } catch (HttpRequestException hre) { _logger.LogException("Get Venue By VenueId service http request error", hre); return(Result.Fail <IVenue>("Get Venue By VenueId service http request error.")); } catch (Exception e) { _logger.LogException("Get Venue By VenueId service unknown error.", e); return(Result.Fail <IVenue>("Get Venue By VenueId service unknown error.")); } finally { _logger.LogMethodExit(); } }
public async Task <IResult <IVenue> > GetVenueByVenueIdAsync(IGetVenueByVenueIdCriteria criteria) { Throw.IfNull(criteria, nameof(criteria)); _logger.LogMethodEnter(); try { _logger.LogInformationObject("Get Venue By VenueId criteria.", criteria); _logger.LogInformationObject("Get Venue By VenueId URI", _getVenueByVenueIdUri); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _settings.ApiKey); var response = await httpClient.GetAsync(_getVenueByVenueIdUri + $"?venueId={criteria.venueId}"); _logger.LogHttpResponseMessage("Get Venue By VenueId service http response", response); if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); _logger.LogInformationObject("Get Venue By VenueId service json response", json); var settings = new JsonSerializerSettings { ContractResolver = new VenueSearchResultContractResolver() }; var venue = JsonConvert.DeserializeObject <Venue>(json, settings); return(Result.Ok <IVenue>(venue)); } else { return(Result.Fail <IVenue>("Get Venue By VenueId service unsuccessful http response")); } } catch (HttpRequestException hre) { _logger.LogException("Get Venue By VenueId service http request error", hre); return(Result.Fail <IVenue>("Get Venue By VenueId service http request error.")); } catch (Exception e) { _logger.LogException("Get Venue By VenueId service unknown error.", e); return(Result.Fail <IVenue>("Get Venue By VenueId service unknown error.")); } finally { _logger.LogMethodExit(); } }