Primera subida
This commit is contained in:
57
back/Application/Services/WantItAllService.cs
Normal file
57
back/Application/Services/WantItAllService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using back.Entities.DTOs.Response;
|
||||
using back.Entities;
|
||||
using back.Application.Contracts.Services;
|
||||
using back.Application.Contracts.Persistence;
|
||||
|
||||
namespace back.Application.Services
|
||||
{
|
||||
public class WantItAllService : IWantItAllService
|
||||
{
|
||||
private readonly IAsyncRepository<Persona> personaRepo;
|
||||
private readonly IAsyncRepository<Casa> casaRepo;
|
||||
private readonly IAsyncRepository<Direccion> direccionRepo;
|
||||
|
||||
public WantItAllService(IAsyncRepository<Persona> personaRepo, IAsyncRepository<Casa> casaRepo, IAsyncRepository<Direccion> direccionRepo)
|
||||
{
|
||||
this.personaRepo = personaRepo;
|
||||
this.casaRepo = casaRepo;
|
||||
this.direccionRepo = direccionRepo;
|
||||
}
|
||||
|
||||
public async Task<IWantItAll> GetWithAsyncAwait()
|
||||
{
|
||||
var personas = await personaRepo.GetAllAsync();
|
||||
var casas = await casaRepo.GetAllAsync();
|
||||
var direcciones = await direccionRepo.GetAllAsync();
|
||||
|
||||
var toReturn = new IWantItAll
|
||||
{
|
||||
Personas = personas.ToList(),
|
||||
Casas = casas.ToList(),
|
||||
Direcciones = direcciones.ToList(),
|
||||
};
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public async Task<IWantItAll> GetWithTasks()
|
||||
{
|
||||
var personas = personaRepo.GetAllAsync();
|
||||
var casas = casaRepo.GetAllAsync();
|
||||
var direcciones = direccionRepo.GetAllAsync();
|
||||
|
||||
await Task.WhenAll(personas, casas, direcciones);
|
||||
|
||||
|
||||
IReadOnlyList<Persona> personas1 = await personas;
|
||||
IReadOnlyList<Casa> casas1 = await casas;
|
||||
IReadOnlyList<Direccion> direccions = await direcciones;
|
||||
var toReturn = new IWantItAll
|
||||
{
|
||||
Personas = personas1.ToList(),
|
||||
Casas = casas1.ToList(),
|
||||
Direcciones = direccions.ToList(),
|
||||
};
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user