Files
FA_WEB/SytelineSaAppEfDataModel/Services/WzRowMareliService.cs

36 lines
1.2 KiB
C#

using AutoMapper;
using Microsoft.EntityFrameworkCore;
using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Entities;
namespace SytelineSaAppEfDataModel.Services;
public class WzRowMareliService(SytelineSaAppDbContext context, IMapper mapper) : IWzRowMareliService
{
public async Task<IEnumerable<WzRowMarelliDto>> GetAll()
{
return await context.WzRowsMeyle.Select(x => mapper.Map<WzRowMarelliDto>(x)).ToListAsync();
}
public async Task CreateRows(IEnumerable<WzRowMarelliDto> rows)
{
var entities = mapper.Map<IEnumerable<WzRowMarelli>>(rows);
await context.WzRowsMareli.AddRangeAsync(entities);
await context.SaveChangesAsync();
}
public async Task<IEnumerable<WzRowMarelliDto>> GetByWzHeaderId(Guid wzHeaderId)
{
return await context.WzRowsMareli
.Where(x => x.FKHeader == wzHeaderId)
.Select(x => mapper.Map<WzRowMarelliDto>(x))
.ToListAsync();
}
public async Task UpdateRows(IEnumerable<WzRowMarelliDto> rows)
{
var entities = mapper.Map<IEnumerable<WzRowMarelli>>(rows);
context.WzRowsMareli.UpdateRange(entities);
await context.SaveChangesAsync();
}
}