64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
namespace EgwCoreLib.Lux.Data.Repository.Config
|
|
{
|
|
public class ConfWoodRepository : BaseRepository, IConfWoodRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ConfWoodRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public async Task<bool> AddAsync(WoodModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
await dbCtx.DbSetConfWood.AddAsync(entity);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
public async Task<bool> DeleteAsync(WoodModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
dbCtx.DbSetConfWood.Remove(entity);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
public async Task<List<WoodModel>> GetAllAsync()
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetConfWood
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<WoodModel?> GetByIdAsync(int recId)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetConfWood
|
|
.Where(x => x.WoodID == recId)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<bool> UpdateAsync(WoodModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
var trackedEntity = await dbCtx.DbSetConfWood.FirstOrDefaultAsync(x => x.WoodID == entity.WoodID);
|
|
|
|
if (trackedEntity != null)
|
|
{
|
|
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
|
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
|
}
|
|
else
|
|
{
|
|
dbCtx.DbSetConfWood.Update(entity);
|
|
}
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |