81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
namespace EgwCoreLib.Lux.Data.Repository.Config
|
|
{
|
|
public class ConfProfileRepository : BaseRepository, IConfProfileRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ConfProfileRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> AddAsync(ProfileModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
await dbCtx.DbSetConfProfile.AddAsync(entity);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> AddRangeAsync(List<ProfileModel> entityList)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
await dbCtx.DbSetConfProfile.AddRangeAsync(entityList);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DeleteAsync(ProfileModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
dbCtx.DbSetConfProfile.Remove(entity);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
/// <inheritdoc />
|
|
public async Task<List<ProfileModel>> GetAllAsync()
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetConfProfile.AsNoTracking().ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ProfileModel?> GetByIdAsync(int recId)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetConfProfile
|
|
.FirstOrDefaultAsync(x => x.ProfileID == recId);
|
|
}
|
|
/// <inheritdoc />
|
|
public async Task<ProfileModel?> GetByUidAsync(string uID)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetConfProfile
|
|
.FirstOrDefaultAsync(x => x.Code == uID);
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> UpdateAsync(ProfileModel entity)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
var trackedEntity = await dbCtx.DbSetConfProfile.FirstOrDefaultAsync(x => x.ProfileID == entity.ProfileID);
|
|
|
|
if (trackedEntity != null)
|
|
{
|
|
// Aggiorna i valori dell'entità tracciata con quelli della nuova
|
|
dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity);
|
|
}
|
|
else
|
|
{
|
|
dbCtx.DbSetConfProfile.Update(entity);
|
|
}
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |