51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
|
using DamageAssesment.Api.UsersAccess.Interfaces;
|
|||
|
using DamageAssesment.Api.UsersAccess.Models;
|
|||
|
using Newtonsoft.Json;
|
|||
|
|
|||
|
namespace DamageAssesment.Api.UsersAccess.Services
|
|||
|
{
|
|||
|
public class EmployeeServiceProvider : ServiceProviderBase, IEmployeeServiceProvider
|
|||
|
{
|
|||
|
public EmployeeServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Employee"), configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase"))
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public async Task<List<Employee>> getEmployeesAsync()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|||
|
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString);
|
|||
|
|
|||
|
if (employees == null || !employees.Any())
|
|||
|
return new List<Employee>();
|
|||
|
else return employees;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()");
|
|||
|
return new List<Employee>();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public async Task<Employee> getEmployeeAsync(int employeeId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId);
|
|||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|||
|
var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString);
|
|||
|
|
|||
|
if (employee == null)
|
|||
|
return null;
|
|||
|
else return employee;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeeAsync()");
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|