public static async Task <PersonaDTO> Handle(GetPersonaQuery request, ITestNetDbContext _context) { var entity = await _context.Personas .Include(p => p.Empleo) .Where(p => p.Id == request.PersonaId) .SingleOrDefaultAsync(); if (entity == null) { throw new NotFoundException("Persona", request.PersonaId); } return(PersonaDTO.Create(entity)); }
public static async Task <List <PersonaDTO> > Handle(ITestNetDbContext _context) { var entities = await _context.Personas .Include(p => p.Empleo) .ToListAsync(); var personasDto = entities.Select(p => PersonaDTO.Create(p)).ToList(); /* * List<PersonaDTO> personasDto = new List<PersonaDTO>(); * * foreach (var p in entities) * { * personasDto.Add(PersonaDTO.Create(p)); * } */ return(personasDto); }