diff --git a/EgwCoreLib.Lux.Data/Services/Sales/OfferRowService.cs b/EgwCoreLib.Lux.Data/Services/Sales/OfferRowService.cs index 3c0f2382..166186b8 100644 --- a/EgwCoreLib.Lux.Data/Services/Sales/OfferRowService.cs +++ b/EgwCoreLib.Lux.Data/Services/Sales/OfferRowService.cs @@ -104,26 +104,21 @@ namespace EgwCoreLib.Lux.Data.Services.Sales { return await TraceAsync($"{_className}.FixUid", async (activity) => { - List result = new List(); - - // 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(); // 4. Preparo la lista da restituire - result = list2fix + var result = list2fix .Select(x => x.OfferRowDtx) - .ToList() ?? new List(); + .ToList(); // 5. Aggiorno i record foreach (var row in list2fix) @@ -142,6 +137,64 @@ namespace EgwCoreLib.Lux.Data.Services.Sales }); } + /// + /// Effettua fix TipoImg righe child dell' Offer indicato + /// + /// Key + /// + public async Task 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 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 GetByIdAsync(int offerRowId) { return await TraceAsync($"{_className}.GetById", async (activity) => @@ -209,6 +262,40 @@ namespace EgwCoreLib.Lux.Data.Services.Sales }); } + /// + /// Effettua update delle info legate al file per il Offer indicato + /// + /// Riga Offer coi dati da aggiornare + /// + public async Task 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; + }); + } + /// /// Effettua update del valore serializzato della Riga Offer /// @@ -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);