From eed3cb108fd6d610e8f8fd0f27f2578ddcd2e128 Mon Sep 17 00:00:00 2001 From: Alejandro Sarmiento Date: Sat, 6 Apr 2024 04:11:04 +0200 Subject: [PATCH] consulta tonta echale un ojo si te apetece --- .../Contracts/Services/IWantItAllService.cs | 5 ++- back/Application/Services/WantItAllService.cs | 35 +++++++++++++++++++ back/Controllers/IWantItAllController.cs | 9 +++++ back/Entities/DTOs/Request/ConsultaLoca.cs | 8 +++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 back/Entities/DTOs/Request/ConsultaLoca.cs diff --git a/back/Application/Contracts/Services/IWantItAllService.cs b/back/Application/Contracts/Services/IWantItAllService.cs index 0cfd18b..f7bd7d2 100644 --- a/back/Application/Contracts/Services/IWantItAllService.cs +++ b/back/Application/Contracts/Services/IWantItAllService.cs @@ -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 ConsultaLocaAwait(ConsultaLoca dto); Task GetWithAsyncAwait(); Task GetWithTasks(); } diff --git a/back/Application/Services/WantItAllService.cs b/back/Application/Services/WantItAllService.cs index 3c48f17..d4d5205 100644 --- a/back/Application/Services/WantItAllService.cs +++ b/back/Application/Services/WantItAllService.cs @@ -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 ConsultaLocaAwait(ConsultaLoca dto) + { + var includes = new List>> +{ + 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>> +{ + 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 GetWithAsyncAwait() { var personas = await personaRepo.GetAllAsync(); diff --git a/back/Controllers/IWantItAllController.cs b/back/Controllers/IWantItAllController.cs index 9f5597f..4370016 100644 --- a/back/Controllers/IWantItAllController.cs +++ b/back/Controllers/IWantItAllController.cs @@ -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 LocaAwait(ConsultaLoca dto) + { + Entities.Persona holi = await service.ConsultaLocaAwait(dto); + return base.Ok(holi); + } } } diff --git a/back/Entities/DTOs/Request/ConsultaLoca.cs b/back/Entities/DTOs/Request/ConsultaLoca.cs new file mode 100644 index 0000000..ffd7aee --- /dev/null +++ b/back/Entities/DTOs/Request/ConsultaLoca.cs @@ -0,0 +1,8 @@ +namespace back.Entities.DTOs.Request +{ + public class ConsultaLoca + { + public string Calle { get; set; } + public int IdPropietario { get; set; } + } +}