From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../ClienteVinculoRepository.cs | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs') diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs new file mode 100644 index 0000000..460e860 --- /dev/null +++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs @@ -0,0 +1,112 @@ +using AutoMapper; +using Gestor.Infrastructure.Entities.Generic; +using Gestor.Infrastructure.Entities.Seguros; +using Gestor.Infrastructure.Mappers; +using Gestor.Infrastructure.Repository.Generic; +using Gestor.Infrastructure.Repository.Interface; +using Gestor.Infrastructure.UnitOfWork.Generic; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; + +namespace Gestor.Infrastructure.Repository.Logic +{ + public class ClienteVinculoRepository : GenericRepository, IClienteVinculoRepository, IGenericRepository + { + public ClienteVinculoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + } + + public void Delete(long id) + { + base.Delete(base.FindEntityById(id)); + } + + public List DeleteVinculo(long clienteId, List vinculos) + { + if (vinculos == null) + { + return null; + } + List list = ( + from x in base.All() + where x.Cliente1.Id == clienteId || x.Cliente2.Id == clienteId + select x).ToList().Where((ClienteVinculoDb vinculo) => { + List clienteVinculos = vinculos; + Func u003cu003e9_32 = ClienteVinculoRepository.u003cu003ec.u003cu003e9__3_2; + if (u003cu003e9_32 == null) + { + u003cu003e9_32 = (ClienteVinculo t) => t.Id; + ClienteVinculoRepository.u003cu003ec.u003cu003e9__3_2 = u003cu003e9_32; + } + return !clienteVinculos.Select(u003cu003e9_32).Contains(vinculo.Id); + }).ToList(); + ClienteVinculoRepository clienteVinculoRepository = this; + list.ForEach(new Action(clienteVinculoRepository.Delete)); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public List FindByCliente(long id) + { + List list = ( + from x in base.All() + where x.Cliente1.Id == id || x.Cliente2.Id == id + select x).ToList(); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public ClienteVinculo FindById(long id) + { + ClienteVinculoDb clienteVinculoDb = base.FindEntityById(id); + return ApplicationMapper.Mapper.Map(clienteVinculoDb); + } + + public List Inserir(List vinculos, Cliente cliente) + { + foreach (ClienteVinculo vinculo in vinculos) + { + if (vinculo.Cliente1.Id == cliente.Id || vinculo.Cliente1.Id == 0) + { + vinculo.Cliente1 = cliente; + } + else + { + if (vinculo.Cliente2.Id != cliente.Id && vinculo.Cliente2.Id != 0) + { + continue; + } + vinculo.Cliente2 = cliente; + } + } + List clienteVinculoDbs = ApplicationMapper.Mapper.Map, List>(vinculos); + base.AddRange(clienteVinculoDbs); + return ApplicationMapper.Mapper.Map, List>(clienteVinculoDbs); + } + + public List Merge(List vinculos, Cliente cliente) + { + List clienteVinculoDbs = ApplicationMapper.Mapper.Map, List>(vinculos); + clienteVinculoDbs.ForEach((ClienteVinculoDb x) => { + if (x.Id != 0) + { + base.Merge(x); + return; + } + x.Cliente1 = ApplicationMapper.Mapper.Map(cliente); + this.SaveOrUpdate(x); + }); + return ApplicationMapper.Mapper.Map, List>(clienteVinculoDbs); + } + + public ClienteVinculo SaveOrUpdate(ClienteVinculo clienteVinculo) + { + ClienteVinculoDb clienteVinculoDb = ApplicationMapper.Mapper.Map(clienteVinculo); + this.SaveOrUpdate(clienteVinculoDb); + return ApplicationMapper.Mapper.Map(clienteVinculoDb); + } + } +} \ No newline at end of file -- cgit v1.2.3