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 --- .../VendedorRepository.cs | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorRepository.cs (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorRepository.cs') diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorRepository.cs new file mode 100644 index 0000000..04a6532 --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorRepository.cs @@ -0,0 +1,132 @@ +using AutoMapper; +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 NHibernate; +using NHibernate.Connection; +using NHibernate.Impl; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; +using System.Linq; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; + +namespace Gestor.Infrastructure.Repository.Logic +{ + public class VendedorRepository : GenericRepository, IVendedorRepository, IGenericRepository + { + private readonly GenericUnitOfWork _unitOfWork; + + private const string comandoVendedor = "SELECT idvendedor, nome, corretora, tipoincidenciadesconto, desconto, ativo, idempresa, idcodigobanco, agencia, conta, cpfcnpj, idtipoconta, cpfcnpjtitular, titularconta, obs FROM vendedor WHERE"; + + public VendedorRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + this._unitOfWork = unitOfWork; + } + + public void Delete(long id) + { + base.Delete(base.FindEntityById(id)); + } + + public List Find(bool ativo, long idempresa = 0L) + { + List condicaos = new List() + { + new Condicao() + { + Campo = "idempresa", + Valores = idempresa.CriarValor() + } + }; + List condicaos1 = new List() + { + new Condicao() + { + Campo = "ISNULL(ativo, '1')", + Valores = (ativo ? "1".CriarValor() : "0".CriarValor()) + } + }; + if (idempresa > (long)0) + { + condicaos1.AddRange(condicaos); + } + return this._unitOfWork.Select(condicaos1.CreateParameters(0), "SELECT idvendedor, nome, corretora, tipoincidenciadesconto, desconto, ativo, idempresa, idcodigobanco, agencia, conta, cpfcnpj, idtipoconta, cpfcnpjtitular, titularconta, obs FROM vendedor WHERE", "").MapVendedor(); + } + + public List Find(long idempresa = 0L) + { + return this.Select((idempresa == 0 ? "" : string.Format(" AND idempresa = {0}", idempresa))); + } + + public List Find(string nome, long idempresa = 0L) + { + string str = (idempresa == 0 ? "" : string.Format(" AND idempresa = {0}", idempresa)); + string str1 = string.Concat(" AND UPPER(ISNULL(nome, '')) LIKE '%", nome.ToUpper(), "%'"); + return this.Select(string.Concat(str, str1)); + } + + public Vendedor FindById(long id) + { + VendedorDb vendedorDb = base.FindEntityById(id); + return ApplicationMapper.Mapper.Map(vendedorDb); + } + + public Vendedor FindCorretora() + { + VendedorDb vendedorDb = base.All().FirstOrDefault((VendedorDb x) => x.Corretora); + return ApplicationMapper.Mapper.Map(vendedorDb); + } + + public Vendedor Merge(Vendedor vendedor) + { + VendedorDb vendedorDb = ApplicationMapper.Mapper.Map(vendedor); + base.Merge(vendedorDb); + return ApplicationMapper.Mapper.Map(vendedorDb); + } + + public Vendedor SaveOrUpdate(Vendedor vendedor) + { + VendedorDb vendedorDb = ApplicationMapper.Mapper.Map(vendedor); + this.SaveOrUpdate(vendedorDb); + return ApplicationMapper.Mapper.Map(vendedorDb); + } + + public List Select(string condition) + { + object connection; + DataTable dataTable = new DataTable(); + SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl; + if (sessionFactory != null) + { + connection = sessionFactory.ConnectionProvider.GetConnection(); + } + else + { + connection = null; + } + using (SqlConnection sqlConnection = connection as SqlConnection) + { + using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) + { + Auxiliar.CriarAuxiliar(sqlCommand, false); + sqlCommand.CommandText = string.Concat("SELECT idvendedor, nome, corretora, tipoincidenciadesconto, desconto, ativo, idempresa, idcodigobanco, agencia, conta, cpfcnpj, idtipoconta, cpfcnpjtitular, titularconta, obs FROM vendedor WHERE 1=1 ", condition, " "); + using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) + { + sqlDataAdapter.SelectCommand = sqlCommand; + sqlDataAdapter.Fill(dataTable); + } + } + } + return dataTable.MapVendedor(); + } + } +} \ No newline at end of file -- cgit v1.2.3