80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
namespace EgwCoreLib.Lux.Data.Repository.Supplier
|
|
{
|
|
public class SupplierRepository : BaseRepository, ISupplierRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public SupplierRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> AddAsync(SupplierModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
await dbCtx.DbSetSupplier.AddAsync(entity);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DeleteAsync(SupplierModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
dbCtx.DbSetSupplier.Remove(entity);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<SupplierModel>> GetAllAsync()
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetSupplier
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<SupplierModel?> GetByIdAsync(int recId)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetSupplier
|
|
.Where(x => x.SupplierID == recId)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<SupplierModel>> GetFiltAsync(string CodGroup)
|
|
{
|
|
// FixMet - ToDo: da implementare secondo CodGroup da relazione n-n da implementare
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetSupplier
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> UpdateAsync(SupplierModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
// Recuperiamo l'entità tracciata dal context
|
|
var trackedEntity = await dbCtx.DbSetSupplier.FirstOrDefaultAsync(x => x.SupplierID == entity.SupplierID);
|
|
|
|
if (trackedEntity != null)
|
|
{
|
|
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
|
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
|
}
|
|
else
|
|
{
|
|
dbCtx.DbSetSupplier.Update(entity);
|
|
}
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |