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.CacheHelper;
|
||||||
using Marco.Pms.Model.MongoDBModels;
|
using Marco.Pms.Model.MongoDBModels;
|
||||||
using Marco.Pms.Model.Projects;
|
using Marco.Pms.Model.Projects;
|
||||||
|
using MarcoBMS.Services.Service;
|
||||||
using Project = Marco.Pms.Model.Projects.Project;
|
using Project = Marco.Pms.Model.Projects.Project;
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Helpers
|
namespace Marco.Pms.Services.Helpers
|
||||||
@ -9,90 +10,205 @@ namespace Marco.Pms.Services.Helpers
|
|||||||
{
|
{
|
||||||
private readonly ProjectCache _projectCache;
|
private readonly ProjectCache _projectCache;
|
||||||
private readonly EmployeeCache _employeeCache;
|
private readonly EmployeeCache _employeeCache;
|
||||||
|
private readonly ILoggingService _logger;
|
||||||
|
|
||||||
public CacheUpdateHelper(ProjectCache projectCache, EmployeeCache employeeCache)
|
public CacheUpdateHelper(ProjectCache projectCache, EmployeeCache employeeCache, ILoggingService logger)
|
||||||
{
|
{
|
||||||
_projectCache = projectCache;
|
_projectCache = projectCache;
|
||||||
_employeeCache = employeeCache;
|
_employeeCache = employeeCache;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------ Project Details and Infrastructure Cache ---------------------------------------
|
// ------------------------------------ Project Details and Infrastructure Cache ---------------------------------------
|
||||||
public async Task AddProjectDetails(Project project)
|
public async Task AddProjectDetails(Project project)
|
||||||
{
|
{
|
||||||
await _projectCache.AddProjectDetailsToCache(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)
|
public async Task<bool> UpdateProjectDetailsOnly(Project project)
|
||||||
{
|
{
|
||||||
bool response = await _projectCache.UpdateProjectDetailsOnlyToCache(project);
|
try
|
||||||
return response;
|
{
|
||||||
|
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)
|
public async Task<ProjectMongoDB?> GetProjectDetails(Guid projectId)
|
||||||
{
|
{
|
||||||
var response = await _projectCache.GetProjectDetailsFromCache(projectId);
|
try
|
||||||
return response;
|
{
|
||||||
|
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)
|
public async Task AddBuildngInfra(Guid projectId, Building? building = null, Floor? floor = null, WorkArea? workArea = null, Guid? buildingId = null)
|
||||||
{
|
{
|
||||||
await _projectCache.AddBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
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)
|
public async Task UpdateBuildngInfra(Guid projectId, Building? building = null, Floor? floor = null, WorkArea? workArea = null, Guid? buildingId = null)
|
||||||
{
|
{
|
||||||
var response = await _projectCache.UpdateBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
try
|
||||||
if (!response)
|
|
||||||
{
|
{
|
||||||
await _projectCache.AddBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
var response = await _projectCache.UpdateBuildngInfraToCache(projectId, building, floor, workArea, buildingId);
|
||||||
|
if (!response)
|
||||||
|
{
|
||||||
|
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)
|
public async Task<List<BuildingMongoDB>?> GetBuildingInfra(Guid projectId)
|
||||||
{
|
{
|
||||||
var response = await _projectCache.GetBuildingInfraFromCache(projectId);
|
try
|
||||||
return response;
|
{
|
||||||
|
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 ---------------------------------------
|
// ------------------------------------ Employee Profile Cache ---------------------------------------
|
||||||
public async Task AddApplicationRole(Guid employeeId, List<Guid> roleIds)
|
public async Task AddApplicationRole(Guid employeeId, List<Guid> roleIds)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.AddApplicationRoleToCache(employeeId, 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)
|
public async Task<bool> AddProjects(Guid employeeId, List<Guid> projectIds)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.AddProjectsToCache(employeeId, projectIds);
|
try
|
||||||
return response;
|
{
|
||||||
|
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)
|
public async Task<List<Guid>?> GetProjects(Guid employeeId)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.GetProjectsFromCache(employeeId);
|
try
|
||||||
if (response.Count > 0)
|
|
||||||
{
|
{
|
||||||
return response;
|
var response = await _employeeCache.GetProjectsFromCache(employeeId);
|
||||||
|
if (response.Count > 0)
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Error occured while getting projectIDs to Cache: {Error}", ex.Message);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public async Task<List<Guid>?> GetPermissions(Guid employeeId)
|
public async Task<List<Guid>?> GetPermissions(Guid employeeId)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.GetPermissionsFromCache(employeeId);
|
try
|
||||||
if (response.Count > 0)
|
|
||||||
{
|
{
|
||||||
return response;
|
var response = await _employeeCache.GetPermissionsFromCache(employeeId);
|
||||||
|
if (response.Count > 0)
|
||||||
|
{
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Error occured while getting permissionIds to Cache: {Error}", ex.Message);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public async Task ClearAllProjectIds(Guid employeeId)
|
public async Task ClearAllProjectIds(Guid employeeId)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.ClearAllProjectIdsFromCache(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)
|
public async Task ClearAllPermissionIdsByEmployeeID(Guid employeeId)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.ClearAllPermissionIdsByEmployeeIDFromCache(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)
|
public async Task ClearAllPermissionIdsByRoleId(Guid roleId)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.ClearAllPermissionIdsByRoleIdFromCache(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)
|
public async Task RemoveRoleId(Guid employeeId, Guid roleId)
|
||||||
{
|
{
|
||||||
var response = await _employeeCache.RemoveRoleIdFromCache(employeeId, 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