Add Patch 6 in API
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 3m12s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 3m12s
This commit is contained in:
parent
3493524224
commit
945da30636
@ -10,10 +10,29 @@ namespace Models.Repositories
|
|||||||
{
|
{
|
||||||
private readonly PhronCareOperationsHubContext _context = context;
|
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)
|
public async Task<EAccountType?> GetByNameAsync(string name)
|
||||||
{
|
{
|
||||||
return await _context.Set<EAccountType>()
|
var accountType = await _context.PhSAccountTypes.FirstOrDefaultAsync(a => a.Name == name);
|
||||||
.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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user