DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Responses/Services/EmployeeServiceProvider.cs

52 lines
2.1 KiB
C#
Raw Normal View History

using DamageAssesment.Api.SurveyResponses.Interfaces;
2023-08-15 22:52:30 -05:00
using DamageAssesment.Api.SurveyResponses.Models;
using Microsoft.AspNetCore.Mvc.Routing;
2023-08-15 22:52:30 -05:00
using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services
2023-08-15 22:52:30 -05:00
{
public class EmployeeServiceProvider : ServiceProviderBase, IEmployeeServiceProvider
2023-08-15 22:52:30 -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
{
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())
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()");
return new List<Employee>();
2023-08-15 22:52:30 -05:00
}
}
public async Task<Employee> getEmployeeAsync(int employeeId)
2023-08-15 22:52:30 -05:00
{
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);
2023-08-15 22:52:30 -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;
}
}
}
}