using DamageAssesment.Api.SurveyResponses.Bases; using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.SurveyResponses.Models; using Newtonsoft.Json; using System.Reflection; namespace DamageAssesment.Api.SurveyResponses.Providers { public class EmployeeServiceProvider :ServiceProviderBase, IEmployeeServiceProvider { public EmployeeServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger logger) : base(configuration, httpClient, logger, "/api/Employees", configuration.GetValue("EndPointSettings:EmployeeUrlBase")) { } public async Task> getEmployeesAsync() { try { httpClient.BaseAddress = new Uri(urlBase); var response = await httpClient.GetAsync(ressource); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var employees = JsonConvert.DeserializeObject>(responseString); if (employees == null || !employees.Any()) return null; else return employees; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()"); return null; } } public async Task getEmployeeAsync(string employeeID) { try { httpClient.BaseAddress = new Uri(urlBase); //ressource = ressource + "/" + employeeID; var response = await httpClient.GetAsync("/api/Employees/"+ employeeID); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var employee = JsonConvert.DeserializeObject(responseString); if (employee == null ) return null; else return employee; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeeAsync()"); return null; } } } }