* Added maintaining Products

* Extended DataModels
* Extended API
This commit is contained in:
2025-03-29 21:37:36 +01:00
parent 15b0060c50
commit 0eaf941021
13 changed files with 237 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
using AutoMapper;
using FaKrosnoEfDataModel.Dtos;
using FaKrosnoEfDataModel.Entities;
using Microsoft.EntityFrameworkCore;
namespace FaKrosnoEfDataModel.Services;
public class ProductService : ServiceBase<ProductDto>, IProductService
{
public ProductService(FaKrosnoDbContext context, IMapper mapper) : base(context, mapper)
{
}
public async Task<IEnumerable<ProductDto?>> GetEntities()
{
IList<ProductDto> products = (await GetAll()).ToList();
return products;
}
public async Task<IEnumerable<ProductDto?>> GetEntitiesToFix(string indexName)
{
IList<ProductDto> products = (await GetAll()).ToList();
return products.Where(x => x?.FaIdx == indexName);
}
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();
}
}
}