Files
PersonaCasa/back/Infra/CasaRepository.cs
Alejandro Sarmiento b672887299 Primera subida
2024-04-06 03:32:16 +02:00

54 lines
1.8 KiB
C#

using back.Entities;
using back.Entities.DTOs.Response;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Client;
namespace back.Infra
{
public class CasaRepository : BaseRepository<Casa>
{
private readonly Application_Db_Context context;
private readonly IDbContextFactory<Application_Db_Context> _dbContextFactory;
public CasaRepository(Application_Db_Context _context, IDbContextFactory<Application_Db_Context> dbContextFactory) : base(dbContextFactory, _context)
{
context = _context;
_dbContextFactory = dbContextFactory;
}
public override async Task<Casa> AddAsync(Casa casa)
{
if(casa.Direccion == null)
{
var toReturn = await base.AddAsync(casa);
return toReturn;
}
else
{
await context.Casas.AddAsync(casa);
await context.Direcciones.AddAsync(casa.Direccion);
await context.SaveChangesAsync();
return casa;
}
}
public async Task<IWantItAll> WantItAlls()
{
var personas = Task.Run(async () => { return await context.Personas.ToListAsync(); });
var casas = Task.Run(async () => { return await context.Casas.ToListAsync(); });
var direcciones = Task.Run(async () => { return await context.Direcciones.ToListAsync(); });
await Task.WhenAll(personas, casas, direcciones);
var toReturn = new IWantItAll()
{
Personas = await personas,
Casas = await casas,
Direcciones = await direcciones
};
return toReturn;
}
}
}