From 945da30636b8eb63dc76394e1b2509acb5a6aeb6 Mon Sep 17 00:00:00 2001 From: Leandro Hernan Rojas Date: Thu, 3 Apr 2025 19:37:21 -0300 Subject: [PATCH] Add Patch 6 in API --- .../Repositories/PhSAccountTypeRepository.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Models/Repositories/PhSAccountTypeRepository.cs b/Models/Repositories/PhSAccountTypeRepository.cs index 08b0568..1ec6a4f 100644 --- a/Models/Repositories/PhSAccountTypeRepository.cs +++ b/Models/Repositories/PhSAccountTypeRepository.cs @@ -10,10 +10,29 @@ namespace Models.Repositories { private readonly PhronCareOperationsHubContext _context = context; + public new async Task> GetAllAsync() + { + var accountTypes = await _context.PhSAccountTypes.ToListAsync(); + return accountTypes.Select(at => MapEntity(at)); + } + public async Task GetByNameAsync(string name) { - return await _context.Set() - .FirstOrDefaultAsync(a => a.Name == name); + var accountType = await _context.PhSAccountTypes.FirstOrDefaultAsync(a => a.Name == name); + return accountType != null ? MapEntity(accountType) : null; } + #region Métodos Auxiliares + private static TDestination MapEntity(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 } + }