consulta tonta
echale un ojo si te apetece
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using back.Entities.DTOs.Response;
|
||||
using back.Entities;
|
||||
using back.Entities.DTOs.Request;
|
||||
using back.Entities.DTOs.Response;
|
||||
|
||||
namespace back.Application.Contracts.Services
|
||||
{
|
||||
public interface IWantItAllService
|
||||
{
|
||||
Task<Persona> ConsultaLocaAwait(ConsultaLoca dto);
|
||||
Task<IWantItAll> GetWithAsyncAwait();
|
||||
Task<IWantItAll> GetWithTasks();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using back.Entities;
|
||||
using back.Application.Contracts.Services;
|
||||
using back.Application.Contracts.Persistence;
|
||||
using back.Entities.DTOs.Request;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace back.Application.Services
|
||||
{
|
||||
@@ -18,6 +20,39 @@ namespace back.Application.Services
|
||||
this.direccionRepo = direccionRepo;
|
||||
}
|
||||
|
||||
public async Task<Persona> ConsultaLocaAwait(ConsultaLoca dto)
|
||||
{
|
||||
var includes = new List<Expression<Func<Persona, object>>>
|
||||
{
|
||||
persona => persona.Casas
|
||||
// Nota: Directamente aquí no puedes añadir la Direccion ya que es una propiedad de Casa, no de Persona.
|
||||
};
|
||||
|
||||
var personasConCasas = await personaRepo.GetAsync(
|
||||
predicate: p => p.Casas.Count > 1, // Aquí puedes definir un filtro si es necesario, por ejemplo: persona => persona.Nombre == "John Doe"
|
||||
orderBy: null, // Aquí puedes definir cómo quieres ordenar los resultados, por ejemplo: q => q.OrderBy(persona => persona.Nombre)
|
||||
includes: includes,
|
||||
disableTracking: true
|
||||
);
|
||||
var includes2 = new List<Expression<Func<Casa, object>>>
|
||||
{
|
||||
casa => casa.Direccion
|
||||
// Nota: Directamente aquí no puedes añadir la Direccion ya que es una propiedad de Casa, no de Persona.
|
||||
};
|
||||
|
||||
var casas = await casaRepo.GetAsync(
|
||||
predicate: p => p.Direccion.Calle.ToLower().Contains("falsa"), // Aquí puedes definir un filtro si es necesario, por ejemplo: persona => persona.Nombre == "John Doe"
|
||||
orderBy: null, // Aquí puedes definir cómo quieres ordenar los resultados, por ejemplo: q => q.OrderBy(persona => persona.Nombre)
|
||||
includes: includes2,
|
||||
disableTracking: true
|
||||
);
|
||||
|
||||
var pl = personasConCasas.ToList();
|
||||
var c = casas.ToList();
|
||||
var result = pl.Where(x=>x.Casas.Any(y=>casas.Where(w=>w.Id == y.Id).Any())).ToList();
|
||||
return result.FirstOrDefault();
|
||||
}
|
||||
|
||||
public async Task<IWantItAll> GetWithAsyncAwait()
|
||||
{
|
||||
var personas = await personaRepo.GetAllAsync();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using back.Application.Contracts.Services;
|
||||
using back.Application.Services;
|
||||
using back.Entities.DTOs.Request;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -27,5 +28,13 @@ namespace back.Controllers
|
||||
{
|
||||
return Ok(await service.GetWithTasks());
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("locaAwait")]
|
||||
public async Task<IActionResult> LocaAwait(ConsultaLoca dto)
|
||||
{
|
||||
Entities.Persona holi = await service.ConsultaLocaAwait(dto);
|
||||
return base.Ok(holi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
back/Entities/DTOs/Request/ConsultaLoca.cs
Normal file
8
back/Entities/DTOs/Request/ConsultaLoca.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace back.Entities.DTOs.Request
|
||||
{
|
||||
public class ConsultaLoca
|
||||
{
|
||||
public string Calle { get; set; }
|
||||
public int IdPropietario { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user