Added error handling in cache helper
This commit is contained in:
parent
8c85d92ba6
commit
8521a68c3e
@ -1,6 +1,7 @@
|
||||
using Marco.Pms.CacheHelper;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.Projects;
|
||||
using MarcoBMS.Services.Service;
|
||||
using Project = Marco.Pms.Model.Projects.Project;
|
||||
|
||||
namespace Marco.Pms.Services.Helpers
|
||||
@ -9,33 +10,72 @@ namespace Marco.Pms.Services.Helpers
|
||||
{
|
||||
private readonly ProjectCache _projectCache;
|
||||
private readonly EmployeeCache _employeeCache;
|
||||
private readonly ILoggingService _logger;
|
||||
|
||||
public CacheUpdateHelper(ProjectCache projectCache, EmployeeCache employeeCache)
|
||||
public CacheUpdateHelper(ProjectCache projectCache, EmployeeCache employeeCache, ILoggingService logger)
|
||||
{
|
||||
_projectCache = projectCache;
|
||||
_employeeCache = employeeCache;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// ------------------------------------ Project Details and Infrastructure Cache ---------------------------------------
|
||||
public async Task AddProjectDetails(Project project)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _projectCache.AddProjectDetailsToCache(project);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while adding project to Cache: {Error}", ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<bool> UpdateProjectDetailsOnly(Project project)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool response = await _projectCache.UpdateProjectDetailsOnlyToCache(project);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while updating project to Cache: {Error}", ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public async Task<ProjectMongoDB?> GetProjectDetails(Guid projectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _projectCache.GetProjectDetailsFromCache(projectId);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while getting project to Cache: {Error}", ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//public async Task<List<ProjectMongoDB>?> GetProjectDetailsList(List<Guid> projectIds)
|
||||
//{
|
||||
// var response = await _projectCache.GetProjectDetailsListFromCache(projectIds);
|
||||
// return response;
|
||||
//}
|
||||
public async Task AddBuildngInfra(Guid projectId, Building? building = null, Floor? floor = null, WorkArea? workArea = null, Guid? buildingId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _projectCache.AddBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while adding project infra to Cache: {Error}", ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task UpdateBuildngInfra(Guid projectId, Building? building = null, Floor? floor = null, WorkArea? workArea = null, Guid? buildingId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _projectCache.UpdateBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
||||
if (!response)
|
||||
@ -43,24 +83,54 @@ namespace Marco.Pms.Services.Helpers
|
||||
await _projectCache.AddBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while updating project infra to Cache: {Error}", ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<List<BuildingMongoDB>?> GetBuildingInfra(Guid projectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _projectCache.GetBuildingInfraFromCache(projectId);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while getting project infra Cache: {Error}", ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------ Employee Profile Cache ---------------------------------------
|
||||
public async Task AddApplicationRole(Guid employeeId, List<Guid> roleIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.AddApplicationRoleToCache(employeeId, roleIds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while adding Application roleIds to Cache to employee {Employee}: {Error}", employeeId, ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<bool> AddProjects(Guid employeeId, List<Guid> projectIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.AddProjectsToCache(employeeId, projectIds);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while adding projectIds to Cache: {Error}", ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public async Task<List<Guid>?> GetProjects(Guid employeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.GetProjectsFromCache(employeeId);
|
||||
if (response.Count > 0)
|
||||
@ -69,7 +139,15 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while getting projectIDs to Cache: {Error}", ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task<List<Guid>?> GetPermissions(Guid employeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.GetPermissionsFromCache(employeeId);
|
||||
if (response.Count > 0)
|
||||
@ -78,21 +156,59 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while getting permissionIds to Cache: {Error}", ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task ClearAllProjectIds(Guid employeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.ClearAllProjectIdsFromCache(employeeId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while deleting projectIds from Cache for employee {EmployeeId}: {Error}", employeeId, ex.Message);
|
||||
}
|
||||
}
|
||||
//public async Task ClearAllProjectIdsByRoleId(Guid roleId)
|
||||
//{
|
||||
// await _employeeCache.ClearAllProjectIdsByRoleIdFromCache(roleId);
|
||||
//}
|
||||
public async Task ClearAllPermissionIdsByEmployeeID(Guid employeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.ClearAllPermissionIdsByEmployeeIDFromCache(employeeId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while deleting permissionIds from to Cache: {Error}", ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task ClearAllPermissionIdsByRoleId(Guid roleId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.ClearAllPermissionIdsByRoleIdFromCache(roleId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while deleting permissionIds from to Cache: {Error}", ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task RemoveRoleId(Guid employeeId, Guid roleId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _employeeCache.RemoveRoleIdFromCache(employeeId, roleId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while deleting Application roleIds from to Cache: {Error}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user