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 --- .../BancosContasRepository.cs | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/BancosContasRepository.cs (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/BancosContasRepository.cs') diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/BancosContasRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/BancosContasRepository.cs new file mode 100644 index 0000000..53fa20c --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/BancosContasRepository.cs @@ -0,0 +1,119 @@ +using AutoMapper; +using Gestor.Infrastructure.Entities.Financeiro; +using Gestor.Infrastructure.Entities.Generic; +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.Domain.Financeiro; +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 BancosContasRepository : GenericRepository, IBancosContasRepository, IGenericRepository + { + private readonly GenericUnitOfWork _unitOfWork; + + public BancosContasRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + this._unitOfWork = unitOfWork; + } + + public void Delete(long id) + { + List list = ( + from x in this._unitOfWork.Query() + where x.Conta.Id == id + select x).ToList(); + if (list.Any()) + { + this._unitOfWork.Repository().DeleteRange(list); + } + BancosContasDb bancosContasDb = base.FindEntityById(id); + if (bancosContasDb == null) + { + return; + } + base.Delete(bancosContasDb); + } + + public List Find(string filter) + { + return this.Select(" AND ISNULL(UPPER(descricao)) LIKE '%filter%'"); + } + + public List Find() + { + return this.Select(""); + } + + public BancosContas FindById(long id) + { + BancosContasDb bancosContasDb = base.FindEntityById(id); + return ApplicationMapper.Mapper.Map(bancosContasDb); + } + + public BancosContas Merge(BancosContas bancosContas) + { + BancosContasDb bancosContasDb = ApplicationMapper.Mapper.Map(bancosContas); + base.Merge(bancosContasDb); + return ApplicationMapper.Mapper.Map(bancosContasDb); + } + + public BancosContas SaveOrUpdate(BancosContas bancosContas) + { + BancosContasDb bancosContasDb = ApplicationMapper.Mapper.Map(bancosContas); + this.SaveOrUpdate(bancosContasDb); + return ApplicationMapper.Mapper.Map(bancosContasDb); + } + + private List Select(string condition) + { + List bancosContas; + 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 * FROM conta WHERE 1=1 ", condition); + using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) + { + sqlDataAdapter.SelectCommand = sqlCommand; + sqlDataAdapter.Fill(dataTable); + } + if (dataTable.Rows.Count != 0) + { + return CustomMap.MapConta(dataTable); + } + else + { + bancosContas = new List(); + } + } + } + return bancosContas; + } + } +} \ No newline at end of file -- cgit v1.2.3