using AutoMapper; using FaKrosnoEfDataModel.Dtos; using FaKrosnoEfDataModel.Entities; using Microsoft.EntityFrameworkCore; namespace FaKrosnoEfDataModel.Services; public class ProductService : ServiceBase, IProductService { public ProductService(FaKrosnoDbContext context, IMapper mapper) : base(context, mapper) { } public async Task> GetEntities() { IList products = (await GetAll()).ToList(); return products; } public async Task> GetEntitiesToFix(string indexName) { IList recipients = (await Context.Recipients.ToListAsync()).Select(x => Mapper.Map(x)).ToList(); IList products = (await GetAll()).ToList(); 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) { Product? product = await Context.Products.FirstOrDefaultAsync(x => x.ID == entity.ID); if (product != null) { product.FaIdx = entity.FaIdx; Context.Products.Update(product); await Context.SaveChangesAsync(); } } }