31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using DamageAssesment.Api.Responses.Interfaces;
|
|
using DamageAssesment.Api.Responses.Models;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace DamageAssesment.Api.Responses.Services
|
|
{
|
|
public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider
|
|
{
|
|
public RegionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<RegionServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Region"), configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
|
{
|
|
}
|
|
public async Task<List<Region>> getRegionsAsync()
|
|
{
|
|
try
|
|
{
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString);
|
|
|
|
if (regions == null || !regions.Any())
|
|
return new List<Region>();
|
|
else return regions;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: RegionServiceProvider.getRegionsAsync()");
|
|
return new List<Region>();
|
|
}
|
|
}
|
|
}
|
|
}
|