From 9f3899813508b00c841cce1c1f6927506ec42f1d Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Wed, 7 May 2025 20:15:20 +0200 Subject: [PATCH] * Fixed issue with wrong Recipient mapping --- FaKrosnoEfDataModel/Dtos/ProductDto.cs | 2 +- .../Services/ProductService.cs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/FaKrosnoEfDataModel/Dtos/ProductDto.cs b/FaKrosnoEfDataModel/Dtos/ProductDto.cs index 26a67eb..d2f00b5 100644 --- a/FaKrosnoEfDataModel/Dtos/ProductDto.cs +++ b/FaKrosnoEfDataModel/Dtos/ProductDto.cs @@ -6,7 +6,7 @@ public class ProductDto : DtoBase public int RecipientID { get; set; } public string RecipientIdx { get; set; } public string FaIdx { get; set; } - public string RecipientName => Recipient.RecipientDesc; + public string RecipientName { get; set; } public RecipientDto Recipient { get; set; } } \ No newline at end of file diff --git a/FaKrosnoEfDataModel/Services/ProductService.cs b/FaKrosnoEfDataModel/Services/ProductService.cs index cebdfa2..1788ea3 100644 --- a/FaKrosnoEfDataModel/Services/ProductService.cs +++ b/FaKrosnoEfDataModel/Services/ProductService.cs @@ -20,9 +20,24 @@ public class ProductService : ServiceBase, IProductService public async Task> GetEntitiesToFix(string indexName) { + IList recipients = + (await Context.Recipients.ToListAsync()).Select(x => Mapper.Map(x)).ToList(); IList products = (await GetAll()).ToList(); - - return products.Where(x => x?.FaIdx == indexName); + + IEnumerable productDtos = products.Where(x => x?.FaIdx == indexName); + + foreach (ProductDto productDto in productDtos) + { + RecipientDto? recipient = recipients.FirstOrDefault(x => x.ID == productDto.RecipientID); + + if (recipient != null) + { + productDto.Recipient = recipient; + productDto.RecipientName = recipient.RecipientDesc; + } + } + + return productDtos; } public async Task UpdateEntity(ProductDto entity)