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<WzRowMareliDto>> GetAll()
{
return await context.WzRowsMeyle.Select(x => mapper.Map<WzRowMareliDto>(x)).ToListAsync();
}
public async Task CreateRows(IEnumerable<WzRowMareliDto> rows)
{
var entities = mapper.Map<IEnumerable<WzRowMareli>>(rows);
await context.WzRowsMareli.AddRangeAsync(entities);
await context.SaveChangesAsync();
}
public async Task<IEnumerable<WzRowMareliDto>> GetByWzHeaderId(Guid wzHeaderId)
{
return await context.WzRowsMareli
.Where(x => x.FKHeader == wzHeaderId)
.Select(x => mapper.Map<WzRowMareliDto>(x))
.ToListAsync();
}
public async Task UpdateRows(IEnumerable<WzRowMareliDto> rows)
{
var entities = mapper.Map<IEnumerable<WzRowMareli>>(rows);
context.WzRowsMareli.UpdateRange(entities);
await context.SaveChangesAsync();
}
}