Merge branch 'feature/MigrateDataLayerService' of https://gitlab.steamware.net/etis/lux into feature/MigrateDataLayerService
This commit is contained in:
@@ -104,26 +104,21 @@ namespace EgwCoreLib.Lux.Data.Services.Sales
|
||||
{
|
||||
return await TraceAsync($"{_className}.FixUid", async (activity) =>
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
|
||||
// 1. Recupero righe
|
||||
var rows = await _repo.GetByParentAsync(offerId);
|
||||
if (rows == null)
|
||||
return result;
|
||||
|
||||
// 2. Trovo quelle da sistemare
|
||||
var list2fix = rows
|
||||
.Where(x => string.IsNullOrEmpty(x.OfferRowUID) || x.OfferRowUID != x.OfferRowDtx)
|
||||
.ToList();
|
||||
|
||||
// 3. Se non c’è nulla da fare → ritorno
|
||||
// 3. Se non c'è nulla da fare → ritorno
|
||||
if (list2fix.Count == 0)
|
||||
return result;
|
||||
return new List<string>();
|
||||
|
||||
// 4. Preparo la lista da restituire
|
||||
result = list2fix
|
||||
var result = list2fix
|
||||
.Select(x => x.OfferRowDtx)
|
||||
.ToList() ?? new List<string>();
|
||||
.ToList();
|
||||
|
||||
// 5. Aggiorno i record
|
||||
foreach (var row in list2fix)
|
||||
@@ -142,6 +137,64 @@ namespace EgwCoreLib.Lux.Data.Services.Sales
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua fix TipoImg righe child dell' Offer indicato
|
||||
/// </summary>
|
||||
/// <param name="offerId">Key</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> FixImgTypeAsync(int offerId)
|
||||
{
|
||||
return await TraceAsync($"{_className}.FixImgType", async (activity) =>
|
||||
{
|
||||
// 1. Recupero righe
|
||||
var rows = await _repo.GetByParentAsync(offerId);
|
||||
if (rows == null) return false;
|
||||
|
||||
// 2. Trovo quelle da sistemare
|
||||
var list2fix = rows
|
||||
.Where(x => x.ImgType == ImageType.ND)
|
||||
.ToList();
|
||||
|
||||
// 3. Se non c'è nulla da fare → ritorno (nessun cambio necessario)
|
||||
if (list2fix.Count == 0)
|
||||
return true;
|
||||
|
||||
|
||||
// 5. Aggiorno i record
|
||||
foreach (var row in list2fix)
|
||||
{
|
||||
// se è calcolato il selling item --> img calcolata
|
||||
if (row.SellingItemNav != null && (row.SellingItemNav.SourceType == ItemSourceType.Jwd || row.SellingItemNav.SourceType == ItemSourceType.FileBTL))
|
||||
{
|
||||
row.ImgType = ImageType.Calculated;
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Salvo
|
||||
bool success = await _repo.SaveRowsAsync(list2fix);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await ClearCacheAsync($"{_redisBaseKey}:Offer:*");
|
||||
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OfferRowModel?> GetByUidAsync(string offerRowUid)
|
||||
{
|
||||
return await TraceAsync($"{_className}.GetByUid", async (activity) =>
|
||||
{
|
||||
return await GetOrSetCacheAsync(
|
||||
$"{_redisBaseKey}:{_className}:ByUid:{offerRowUid}",
|
||||
async () => await _repo.GetByUidAsync(offerRowUid),
|
||||
LongCache
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OfferRowModel?> GetByIdAsync(int offerRowId)
|
||||
{
|
||||
return await TraceAsync($"{_className}.GetById", async (activity) =>
|
||||
@@ -209,6 +262,40 @@ namespace EgwCoreLib.Lux.Data.Services.Sales
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua update delle info legate al file per il Offer indicato
|
||||
/// </summary>
|
||||
/// <param name="updRec">Riga Offer coi dati da aggiornare</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateFileDataAsync(OfferRowModel updRec)
|
||||
{
|
||||
return await TraceAsync($"{_className}.UpdateFileData", async (activity) =>
|
||||
{
|
||||
var currRec = await _repo.GetByIdAsync(updRec.OfferRowID);
|
||||
|
||||
if (currRec == null)
|
||||
return false;
|
||||
|
||||
currRec.FileName = updRec.FileName;
|
||||
currRec.FileResource = updRec.FileResource;
|
||||
currRec.FileSize = updRec.FileSize;
|
||||
currRec.SerStruct = updRec.SerStruct;
|
||||
currRec.ImgType = Core.Enums.ImageType.Calculated;
|
||||
|
||||
activity?.SetTag("db.operation", "UPDATE");
|
||||
|
||||
bool success = await _repo.UpdateAsync(currRec);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await ClearCacheAsync($"{_redisBaseKey}:Offer:*");
|
||||
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
|
||||
}
|
||||
|
||||
return success;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua update del valore serializzato della Riga Offer
|
||||
/// </summary>
|
||||
@@ -347,6 +434,8 @@ namespace EgwCoreLib.Lux.Data.Services.Sales
|
||||
{
|
||||
operation = "INSERT";
|
||||
success = await _repo.AddAsync(upsRec);
|
||||
|
||||
if (!success) return null; // Return null on insert failure
|
||||
}
|
||||
|
||||
activity?.SetTag("db.operation", operation);
|
||||
|
||||
Reference in New Issue
Block a user