54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EgwCoreLib.Lux.Data.Repository.Config
|
|
{
|
|
public class ConfProfileRepository : BaseRepository, IConfProfileRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ConfProfileRepository(DataLayerContext db) : base(db)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public void Add(ProfileModel entity) => _dbCtx.DbSetConfProfile.Add(entity);
|
|
|
|
public void Delete(ProfileModel entity) => _dbCtx.DbSetConfProfile.Remove(entity);
|
|
|
|
public async Task<List<ProfileModel>> GetAllAsync()
|
|
{
|
|
return await _dbCtx.DbSetConfProfile
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<ProfileModel?> GetByIdAsync(int recId)
|
|
{
|
|
return await _dbCtx.DbSetConfProfile
|
|
.Where(x => x.ProfileID == recId)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public void Update(ProfileModel entity)
|
|
{
|
|
// Recuperiamo l'entità tracciata dal context
|
|
var trackedEntity = _dbCtx.DbSetConfProfile.Local.FirstOrDefault(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);
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |