Aggiunta repository x Glass, Profile, Wood e servizi (da integrare)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user