From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../ProspectRepository.cs | 245 +++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ProspectRepository.cs (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ProspectRepository.cs') diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ProspectRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ProspectRepository.cs new file mode 100644 index 0000000..8b4909c --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/ProspectRepository.cs @@ -0,0 +1,245 @@ +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.Common; +using Gestor.Model.Domain.Relatorios; +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 ProspectRepository : GenericRepository, IProspectRepository, IGenericRepository + { + private readonly GenericUnitOfWork _unitOfWork; + + public ProspectRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + this._unitOfWork = unitOfWork; + } + + public void Delete(long id) + { + ProspeccaoDb prospeccaoDb = base.FindEntityById(id); + if (prospeccaoDb == null) + { + return; + } + base.Delete(prospeccaoDb); + } + + public List Find(long idempresa, long id, DateTime inicio, DateTime fim, StatusProspeccao? status) + { + VendedorDb vendedorDb = this._unitOfWork.Query().First((VendedorDb x) => x.Corretora); + List prospeccaoDbs = new List(); + if (status.HasValue) + { + if (idempresa == 0 && id == 0) + { + prospeccaoDbs = ( + from x in base.All() + where (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) && (int?)x.Status == (int?)status + select x).ToList(); + } + if (idempresa == 0 && id > (long)0) + { + prospeccaoDbs = ( + from x in base.All() + where x.Vendedor.Id == id && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) && (int?)x.Status == (int?)status + select x).ToList(); + } + if (idempresa > (long)0 && id == 0) + { + prospeccaoDbs = ( + from x in base.All() + where x.IdEmpresa == idempresa && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) && (int?)x.Status == (int?)status + select x).ToList(); + } + if (idempresa > (long)0 && id > (long)0) + { + prospeccaoDbs = ( + from x in base.All() + where x.IdEmpresa == idempresa && x.Vendedor.Id == id && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) && (int?)x.Status == (int?)status + select x).ToList(); + } + } + else + { + if (idempresa == 0 && id == 0) + { + prospeccaoDbs = ( + from x in base.All() + where (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) + select x).ToList(); + } + if (idempresa == 0 && id > (long)0) + { + prospeccaoDbs = ( + from x in base.All() + where x.Vendedor.Id == id && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) + select x).ToList(); + } + if (idempresa > (long)0 && id == 0) + { + prospeccaoDbs = ( + from x in base.All() + where x.IdEmpresa == idempresa && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) + select x).ToList(); + } + if (idempresa > (long)0 && id > (long)0) + { + prospeccaoDbs = ( + from x in base.All() + where x.IdEmpresa == idempresa && x.Vendedor.Id == id && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) + select x).ToList(); + } + } + foreach (ProspeccaoDb prospeccaoDb in prospeccaoDbs) + { + if (prospeccaoDb.Vendedor == null || prospeccaoDb.Vendedor.Id == 0) + { + prospeccaoDb.Vendedor = vendedorDb; + } + bool? renovacao = prospeccaoDb.Renovacao; + prospeccaoDb.Renovacao = new bool?(renovacao.GetValueOrDefault(true)); + } + return ApplicationMapper.Mapper.Map, List>(prospeccaoDbs); + } + + public List Find(Filtros filtro) + { + List prospeccaoDbs; + VendedorDb vendedorDb = this._unitOfWork.Query().First((VendedorDb x) => x.Corretora); + List statusProspeccaos = new List() + { + StatusProspeccao.Agendado, + StatusProspeccao.EmAndamento, + StatusProspeccao.NaoTrabalhado, + StatusProspeccao.Perdido, + StatusProspeccao.Ganho + }; + if (filtro.Status != null && filtro.Status.Count > 0) + { + statusProspeccaos.RemoveAll((StatusProspeccao x) => true); + if (filtro.Status.Contains((long)1) || filtro.Status.Contains((long)2)) + { + statusProspeccaos.Add(StatusProspeccao.Agendado); + statusProspeccaos.Add(StatusProspeccao.NaoTrabalhado); + statusProspeccaos.Add(StatusProspeccao.EmAndamento); + } + if (filtro.Status.Contains((long)6)) + { + statusProspeccaos.Add(StatusProspeccao.Perdido); + } + if (filtro.Status.Contains((long)5)) + { + statusProspeccaos.Add(StatusProspeccao.Ganho); + } + } + prospeccaoDbs = (filtro.Vendedores == null || filtro.Vendedores.Count <= 0 ? ( + from x in base.All() + where (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)filtro.Inicio) && (x.VigenciaFinal <= (DateTime?)filtro.Fim) && statusProspeccaos.Contains(x.Status.Value) + select x).ToList() : ( + from x in base.All() + where filtro.Vendedores.Contains(x.Vendedor.Id) && (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)filtro.Inicio) && (x.VigenciaFinal <= (DateTime?)filtro.Fim) && statusProspeccaos.Contains(x.Status.Value) + select x).ToList()); + foreach (ProspeccaoDb nullable in prospeccaoDbs) + { + if (nullable.Vendedor == null || nullable.Vendedor.Id == 0) + { + nullable.Vendedor = vendedorDb; + } + bool? renovacao = nullable.Renovacao; + nullable.Renovacao = new bool?(renovacao.GetValueOrDefault(true)); + } + prospeccaoDbs = (filtro.IdEmpresa == 0 ? prospeccaoDbs : ( + from x in prospeccaoDbs + where x.IdEmpresa == filtro.IdEmpresa + select x).ToList()); + return ApplicationMapper.Mapper.Map, List>(prospeccaoDbs); + } + + public List FindByData(DateTime inicio, DateTime fim) + { + List list = ( + from x in base.All() + where (x.VigenciaFinal != null) && (x.VigenciaFinal >= (DateTime?)inicio) && (x.VigenciaFinal <= (DateTime?)fim) + select x).ToList(); + list.ForEach((ProspeccaoDb x) => x.Renovacao = new bool?(x.Renovacao.GetValueOrDefault(true))); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public Prospeccao FindById(long id) + { + ProspeccaoDb nullable = base.FindEntityById(id); + if (nullable != null) + { + bool? renovacao = nullable.Renovacao; + nullable.Renovacao = new bool?(renovacao.GetValueOrDefault(true)); + } + return ApplicationMapper.Mapper.Map(nullable); + } + + public List FindByStatus(StatusProspeccao status) + { + List list = ( + from x in base.All() + where (int?)x.Status == (int?)status + select x).ToList(); + list.ForEach((ProspeccaoDb x) => x.Renovacao = new bool?(x.Renovacao.GetValueOrDefault(true))); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public List FindByStatusPersonalizado(long statusId) + { + List list = ( + from x in base.All() + where x.StatusPersonalizado.Id == statusId + select x).ToList(); + list.ForEach((ProspeccaoDb x) => x.Renovacao = new bool?(x.Renovacao.GetValueOrDefault(true))); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public Prospeccao FindByTarefa(long id) + { + ProspeccaoDb nullable = base.All().FirstOrDefault((ProspeccaoDb x) => x.Tarefa.Id == id); + if (nullable != null) + { + bool? renovacao = nullable.Renovacao; + nullable.Renovacao = new bool?(renovacao.GetValueOrDefault(true)); + } + return ApplicationMapper.Mapper.Map(nullable); + } + + public List FindByVendedor(long id) + { + List list = ( + from x in base.All() + where x.Vendedor.Id == id + select x).ToList(); + list.ForEach((ProspeccaoDb x) => x.Renovacao = new bool?(x.Renovacao.GetValueOrDefault(true))); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public Prospeccao Merge(Prospeccao prospeccao) + { + ProspeccaoDb prospeccaoDb = ApplicationMapper.Mapper.Map(prospeccao); + base.Merge(prospeccaoDb); + return ApplicationMapper.Mapper.Map(prospeccaoDb); + } + + public Prospeccao SaveOrUpdate(Prospeccao prospeccao) + { + ProspeccaoDb prospeccaoDb = ApplicationMapper.Mapper.Map(prospeccao); + this.SaveOrUpdate(prospeccaoDb); + return ApplicationMapper.Mapper.Map(prospeccaoDb); + } + } +} \ No newline at end of file -- cgit v1.2.3