Primera subida

This commit is contained in:
Alejandro Sarmiento
2024-04-06 03:32:16 +02:00
parent c97b4a8179
commit b672887299
44 changed files with 44426 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
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;
}
}
}