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 --- .../AdiantamentoRepository.cs | 168 +++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AdiantamentoRepository.cs (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AdiantamentoRepository.cs') diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AdiantamentoRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AdiantamentoRepository.cs new file mode 100644 index 0000000..aff2bf7 --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AdiantamentoRepository.cs @@ -0,0 +1,168 @@ +using AutoMapper; +using Gestor.Infrastructure.Entities.Generic; +using Gestor.Infrastructure.Entities.Seguros; +using Gestor.Infrastructure.Helpers; +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.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 AdiantamentoRepository : GenericRepository, IAdiantamentoRepository, IGenericRepository + { + private readonly GenericUnitOfWork _unitOfWork; + + public AdiantamentoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + this._unitOfWork = unitOfWork; + } + + public List AddRange(List adiantamentos) + { + List adiantamentoDbs = ApplicationMapper.Mapper.Map, List>(adiantamentos); + base.AddRange(adiantamentoDbs); + return ApplicationMapper.Mapper.Map, List>(adiantamentoDbs); + } + + public List BuscarAdiantamentos(long id, bool concluido = false) + { + List list = ( + from x in base.All() + where x.Vendedor.Id == id && x.Pago == concluido + select x).ToList(); + return ApplicationMapper.Mapper.Map, List>(list); + } + + public void Delete(long id) + { + base.Delete(base.FindEntityById(id)); + } + + public List Find(bool ativo) + { + return this.Select((new List() + { + new Condicao() + { + Campo = "ativo", + Valores = null + }, + new Condicao() + { + Campo = "pago", + Valores = "1".CriarValor() + } + }).CreateParameters(0)); + } + + public List Find(long id) + { + return this.Select((new List() + { + new Condicao() + { + Campo = "idvendedor", + Valores = id.CriarValor() + } + }).CreateParameters(0)); + } + + public List Find(string nome) + { + return this.Select((new List() + { + new Condicao() + { + Campo = "historico", + Valores = nome.CriarValor() + } + }).CreateParameters(0)); + } + + public List FindByDate(DateTime inicio, DateTime fim, List vendedores = null, bool segundavia = false) + { + List condicaos = new List() + { + new Condicao() + { + Campo = (segundavia ? "CAST(Pagamento AS DATE)" : "CAST(data AS DATE)"), + Valores = inicio.CriarValor(), + Operador = Operador.MaiorEIgual + }, + new Condicao() + { + Campo = (segundavia ? "CAST(Pagamento AS DATE)" : "CAST(data AS DATE)"), + Valores = fim.CriarValor(), + Operador = Operador.MenorEIgual + } + }; + condicaos.AddRange((!segundavia ? new List() + { + new Condicao() + { + Campo = "pago", + Valores = null, + Operacao = Operacao.Or, + Grupo = 1 + }, + new Condicao() + { + Campo = "pago", + Valores = "1".CriarValor(), + Operacao = Operacao.Or, + Grupo = 1, + Operador = Operador.Diferente + } + } : new List() + { + new Condicao() + { + Campo = "pago", + Valores = "1".CriarValor() + } + })); + if (vendedores != null && vendedores.Count > 0) + { + condicaos.Add(new Condicao() + { + Campo = "idvendedor", + Valores = vendedores.CriarValor() + }); + } + return this.Select(condicaos.CreateParameters(0)); + } + + public Adiantamento FindById(long id) + { + AdiantamentoDb adiantamentoDb = base.FindEntityById(id); + return ApplicationMapper.Mapper.Map(adiantamentoDb); + } + + public Adiantamento Merge(Adiantamento adiantamento) + { + AdiantamentoDb adiantamentoDb = ApplicationMapper.Mapper.Map(adiantamento); + base.Merge(adiantamentoDb); + return ApplicationMapper.Mapper.Map(adiantamentoDb); + } + + public Adiantamento SaveOrUpdate(Adiantamento adiantamento) + { + AdiantamentoDb adiantamentoDb = ApplicationMapper.Mapper.Map(adiantamento); + this.SaveOrUpdate(adiantamentoDb); + return ApplicationMapper.Mapper.Map(adiantamentoDb); + } + + private List Select(SqlQueryCondition sqlCondition) + { + return this._unitOfWork.Select(sqlCondition, "SELECT DISTINCT * FROM adiantamento WHERE", "").MapAdiantamento(); + } + } +} \ No newline at end of file -- cgit v1.2.3