107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
namespace EgwCoreLib.Lux.Data.Services.Utils
|
|
{
|
|
public class GenValService : BaseServ, IGenValService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public GenValService(
|
|
IConfiguration config,
|
|
IConnectionMultiplexer redis,
|
|
IGenValRepository repo) : base(config, redis)
|
|
{
|
|
_className = "GenVal";
|
|
_repo = repo;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DeleteAsync(GenValueModel rec2del)
|
|
{
|
|
return await TraceAsync($"{_className}.Delete", async (activity) =>
|
|
{
|
|
bool success = await _repo.DeleteAsync(rec2del);
|
|
|
|
if (success)
|
|
{
|
|
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
|
|
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
|
}
|
|
|
|
return success;
|
|
});
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<GenValueModel>> GetFiltAsync(string codClass)
|
|
{
|
|
return await TraceAsync($"{_className}.GetFilt", async (activity) =>
|
|
{
|
|
return await GetOrSetCacheAsync(
|
|
$"{_redisBaseKey}:{_className}:{codClass}",
|
|
async () => await _repo.GetFiltAsync(codClass),
|
|
UltraLongCache
|
|
);
|
|
});
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> MoveAsync(GenValueModel selRec, bool moveUp)
|
|
{
|
|
return await TraceAsync($"{_className}.MoveAsync", async (activity) =>
|
|
{
|
|
bool success = await _repo.MoveAsync(selRec, moveUp);
|
|
|
|
if (success)
|
|
{
|
|
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
|
|
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
|
}
|
|
|
|
return success;
|
|
});
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> UpsertAsync(GenValueModel upsRec)
|
|
{
|
|
return await TraceAsync($"{_className}.Upsert", async (activity) =>
|
|
{
|
|
var currRec = await _repo.GetByIdAsync(upsRec.GenValID);
|
|
|
|
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}:GenClass*");
|
|
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
|
}
|
|
|
|
return success;
|
|
});
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly string _className;
|
|
private readonly IGenValRepository _repo;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |