33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using Distribution.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.Uom;
|
|
|
|
public class UomRepository(AppDBContext context) : IUomRepository
|
|
{
|
|
public async Task<Models.Uom?> GetByIdAsync(Guid id) =>
|
|
await context.Uoms.FindAsync(id);
|
|
|
|
public async Task<List<Models.Uom>> GetAllAsync() =>
|
|
await context.Uoms.ToListAsync();
|
|
|
|
public async Task<Models.Uom?> GetByExternalErpIdAsync(int erpId) =>
|
|
await context.Uoms.FirstOrDefaultAsync(u => u.ExternalErpId == erpId);
|
|
|
|
public async Task<bool> IsUsedByItemsAsync(Guid id) =>
|
|
await context.Items.AnyAsync(i => i.FK_BaseUomId == id && i.IsActive) ||
|
|
await context.UomConversions.AnyAsync(c => c.FK_FromUomId == id || c.FK_ToUomId == id);
|
|
|
|
public async Task AddAsync(Models.Uom entity) =>
|
|
await context.Uoms.AddAsync(entity);
|
|
|
|
public void Update(Models.Uom entity) =>
|
|
context.Uoms.Update(entity);
|
|
|
|
public void Remove(Models.Uom entity)
|
|
{
|
|
entity.IsActive = false;
|
|
context.Uoms.Update(entity);
|
|
}
|
|
}
|