Add Patch 6 in API
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 3m12s

This commit is contained in:
Leandro Hernan Rojas 2025-04-03 19:37:21 -03:00
parent 3493524224
commit 945da30636

View File

@ -10,10 +10,29 @@ namespace Models.Repositories
{
private readonly PhronCareOperationsHubContext _context = context;
public new async Task<IEnumerable<EAccountType>> GetAllAsync()
{
var accountTypes = await _context.PhSAccountTypes.ToListAsync();
return accountTypes.Select(at => MapEntity<PhSAccountType, EAccountType>(at));
}
public async Task<EAccountType?> GetByNameAsync(string name)
{
return await _context.Set<EAccountType>()
.FirstOrDefaultAsync(a => a.Name == name);
var accountType = await _context.PhSAccountTypes.FirstOrDefaultAsync(a => a.Name == name);
return accountType != null ? MapEntity<PhSAccountType, EAccountType>(accountType) : null;
}
#region Métodos Auxiliares
private static TDestination MapEntity<TSource, TDestination>(TSource source) where TDestination : new()
{
var destination = new TDestination();
foreach (var propertyInfo in typeof(TSource).GetProperties())
{
var value = propertyInfo.GetValue(source);
typeof(TDestination).GetProperty(propertyInfo.Name)?.SetValue(destination, value);
}
return destination;
}
#endregion
}
}