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 /// public async Task 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; }); } /// public async Task> GetFiltAsync(string codClass) { return await TraceAsync($"{_className}.GetFilt", async (activity) => { return await GetOrSetCacheAsync( $"{_redisBaseKey}:{_className}:{codClass}", async () => await _repo.GetFiltAsync(codClass), UltraLongCache ); }); } /// public async Task 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; }); } /// public async Task 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 } }