2023-09-04 20:59:21 -05:00
|
|
|
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using DamageAssesment.Api.SurveyResponses.Models;
|
2023-09-13 00:28:24 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2023-09-04 20:59:21 -05:00
|
|
|
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public class EmployeeServiceProvider : ServiceProviderBase, IEmployeeServiceProvider
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public EmployeeServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Employee"), configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase"))
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<Employee>> getEmployeesAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (employees == null || !employees.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Employee>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return employees;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Employee>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public async Task<Employee> getEmployeeAsync(int employeeId)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-09-13 00:28:24 -05:00
|
|
|
|
if (employee == null)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
return null;
|
|
|
|
|
else return employee;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeeAsync()");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|