namespace EgwCoreLib.Lux.Data.Services.Job
{
public class JobStepService : BaseServ, IJobStepService
{
#region Public Constructors
public JobStepService(
IConfiguration config,
IConnectionMultiplexer redis,
IJobStepRepository repo) : base(config, redis)
{
_className = "JobStep";
_repo = repo;
}
#endregion Public Constructors
#region Public Methods
///
public async Task DeleteAsync(JobStepModel rec2del)
{
return await TraceAsync($"{_className}.Delete", async (activity) =>
{
var dbResult = await _repo.GetByIdAsync(rec2del.JobStepID);
if (dbResult == null) return false;
bool success = await _repo.DeleteAsync(dbResult);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:{_className}*");
await ClearCacheAsync($"{_redisBaseKey}:JobTaskList:*");
await ClearCacheAsync($"{_redisBaseKey}:Resources:*");
}
return success;
});
}
///
public async Task> GetByParentAsync(int jobID)
{
return await TraceAsync($"{_className}.GetByParent", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:{_className}:{jobID}",
async () => await _repo.GetByParentAsync(jobID),
UltraLongCache
);
});
}
///
public async Task MoveAsync(JobStepModel selRec, bool moveUp)
{
return await TraceAsync($"{_className}.Move", async (activity) =>
{
var currRec = await _repo.GetByIdAsync(selRec.JobStepID);
if (currRec == null) return false;
string operation = "Move";
bool success = await _repo.MoveAsync(selRec, moveUp);
if (currRec != null)
activity?.SetTag("db.operation", operation);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:{_className}*");
await ClearCacheAsync($"{_redisBaseKey}:JobTaskList:*");
await ClearCacheAsync($"{_redisBaseKey}:Resources:*");
}
return success;
});
}
///
public async Task UpsertAsync(JobStepModel upsRec)
{
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetByIdAsync(upsRec.JobStepID);
string operation = "UPDATE";
bool success = false;
if (currRec != null)
{
success = await _repo.UpdateAsync(upsRec);
}
else
{
operation = "INSERT";
success = await _repo.AddAsync(upsRec);
}
activity?.SetTag("db.operation", operation);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:{_className}*");
await ClearCacheAsync($"{_redisBaseKey}:JobTaskList:*");
await ClearCacheAsync($"{_redisBaseKey}:Resources:*");
}
return success;
});
}
#endregion Public Methods
#region Private Fields
private readonly string _className;
private readonly IJobStepRepository _repo;
#endregion Private Fields
}
}