summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs')
-rw-r--r--Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs112
1 files changed, 112 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ClienteVinculoRepository.cs
new file mode 100644
index 0000000..460e860
--- /dev/null
+++ b/Codemerx/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<ClienteVinculoDb>, IClienteVinculoRepository, IGenericRepository<ClienteVinculoDb>
+ {
+ public ClienteVinculoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ }
+
+ public void Delete(long id)
+ {
+ base.Delete(base.FindEntityById(id));
+ }
+
+ public List<ClienteVinculo> DeleteVinculo(long clienteId, List<ClienteVinculo> vinculos)
+ {
+ if (vinculos == null)
+ {
+ return null;
+ }
+ List<ClienteVinculoDb> list = (
+ from x in base.All()
+ where x.Cliente1.Id == clienteId || x.Cliente2.Id == clienteId
+ select x).ToList<ClienteVinculoDb>().Where<ClienteVinculoDb>((ClienteVinculoDb vinculo) => {
+ List<ClienteVinculo> clienteVinculos = vinculos;
+ Func<ClienteVinculo, long> 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<ClienteVinculo, long>(u003cu003e9_32).Contains<long>(vinculo.Id);
+ }).ToList<ClienteVinculoDb>();
+ ClienteVinculoRepository clienteVinculoRepository = this;
+ list.ForEach(new Action<ClienteVinculoDb>(clienteVinculoRepository.Delete));
+ return ApplicationMapper.Mapper.Map<List<ClienteVinculoDb>, List<ClienteVinculo>>(list);
+ }
+
+ public List<ClienteVinculo> FindByCliente(long id)
+ {
+ List<ClienteVinculoDb> list = (
+ from x in base.All()
+ where x.Cliente1.Id == id || x.Cliente2.Id == id
+ select x).ToList<ClienteVinculoDb>();
+ return ApplicationMapper.Mapper.Map<List<ClienteVinculoDb>, List<ClienteVinculo>>(list);
+ }
+
+ public ClienteVinculo FindById(long id)
+ {
+ ClienteVinculoDb clienteVinculoDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<ClienteVinculoDb, ClienteVinculo>(clienteVinculoDb);
+ }
+
+ public List<ClienteVinculo> Inserir(List<ClienteVinculo> 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<ClienteVinculoDb> clienteVinculoDbs = ApplicationMapper.Mapper.Map<List<ClienteVinculo>, List<ClienteVinculoDb>>(vinculos);
+ base.AddRange(clienteVinculoDbs);
+ return ApplicationMapper.Mapper.Map<List<ClienteVinculoDb>, List<ClienteVinculo>>(clienteVinculoDbs);
+ }
+
+ public List<ClienteVinculo> Merge(List<ClienteVinculo> vinculos, Cliente cliente)
+ {
+ List<ClienteVinculoDb> clienteVinculoDbs = ApplicationMapper.Mapper.Map<List<ClienteVinculo>, List<ClienteVinculoDb>>(vinculos);
+ clienteVinculoDbs.ForEach((ClienteVinculoDb x) => {
+ if (x.Id != 0)
+ {
+ base.Merge(x);
+ return;
+ }
+ x.Cliente1 = ApplicationMapper.Mapper.Map<Cliente, ClienteDb>(cliente);
+ this.SaveOrUpdate(x);
+ });
+ return ApplicationMapper.Mapper.Map<List<ClienteVinculoDb>, List<ClienteVinculo>>(clienteVinculoDbs);
+ }
+
+ public ClienteVinculo SaveOrUpdate(ClienteVinculo clienteVinculo)
+ {
+ ClienteVinculoDb clienteVinculoDb = ApplicationMapper.Mapper.Map<ClienteVinculo, ClienteVinculoDb>(clienteVinculo);
+ this.SaveOrUpdate(clienteVinculoDb);
+ return ApplicationMapper.Mapper.Map<ClienteVinculoDb, ClienteVinculo>(clienteVinculoDb);
+ }
+ }
+} \ No newline at end of file