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 --- .../PlanoRepository.cs | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanoRepository.cs (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanoRepository.cs') diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanoRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanoRepository.cs new file mode 100644 index 0000000..47044d1 --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanoRepository.cs @@ -0,0 +1,93 @@ +using AutoMapper; +using Gestor.Infrastructure.Entities.Financeiro; +using Gestor.Infrastructure.Entities.Generic; +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 Gestor.Model.Domain.Generic; +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.Reflection; +using System.Runtime.CompilerServices; + +namespace Gestor.Infrastructure.Repository.Logic +{ + public class PlanoRepository : GenericRepository, IPlanoRepository, IGenericRepository + { + private readonly GenericUnitOfWork _unitOfWork; + + public PlanoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) + { + this._unitOfWork = unitOfWork; + } + + public List Find(string filter) + { + PlanoRepository.u003cu003ec__DisplayClass2_0 variable = null; + IQueryable planoDbs = base.All(); + ParameterExpression parameterExpression = Expression.Parameter(typeof(PlanoDb), "x"); + IQueryable planoDbs1 = planoDbs.Where(Expression.Lambda>(Expression.AndAlso(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(PlanoDb).GetMethod("get_Ativo").MethodHandle)), Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(PlanoDb).GetMethod("get_Descricao").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("ToUpper").MethodHandle), Array.Empty()), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(PlanoRepository.u003cu003ec__DisplayClass2_0)), FieldInfo.GetFieldFromHandle(typeof(PlanoRepository.u003cu003ec__DisplayClass2_0).GetField("filter").FieldHandle)) })), new ParameterExpression[] { parameterExpression })); + parameterExpression = Expression.Parameter(typeof(PlanoDb), "x"); + return planoDbs1.Select(Expression.Lambda>(Expression.MemberInit(Expression.New(typeof(Plano)), new MemberBinding[] { Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(DomainBase).GetMethod("set_Id", new Type[] { typeof(long) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EntityBase).GetMethod("get_Id").MethodHandle))), Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Plano).GetMethod("set_Descricao", new Type[] { typeof(string) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(PlanoDb).GetMethod("get_Descricao").MethodHandle))), Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Plano).GetMethod("set_Ativo", new Type[] { typeof(bool) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(PlanoDb).GetMethod("get_Ativo").MethodHandle))) }), new ParameterExpression[] { parameterExpression })).ToList(); + } + + public List Find() + { + object connection; + SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl; + DataTable dataTable = new DataTable(); + if (sessionFactory != null) + { + connection = sessionFactory.ConnectionProvider.GetConnection(); + } + else + { + connection = null; + } + using (SqlConnection sqlConnection = connection as SqlConnection) + { + using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = "SELECT DISTINCT idcplano as id, descricao as nome, ativo FROM cplano;"; + using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter()) + { + sqlDataAdapter.SelectCommand = sqlCommand; + sqlDataAdapter.Fill(dataTable); + } + } + } + return ( + from a in dataTable.AsEnumerable().ToList() + select new Plano() + { + Id = a.Field("id"), + Descricao = a.Field("nome"), + Ativo = (a.Field("ativo") == null ? true : a.Field("ativo").ToString() == "1") + }).ToList(); + } + + public Plano Merge(Plano plano) + { + PlanoDb planoDb = ApplicationMapper.Mapper.Map(plano); + base.Merge(planoDb); + return ApplicationMapper.Mapper.Map(planoDb); + } + + public Plano SaveOrUpdate(Plano plano) + { + PlanoDb planoDb = ApplicationMapper.Mapper.Map(plano); + this.SaveOrUpdate(planoDb); + return ApplicationMapper.Mapper.Map(planoDb); + } + } +} \ No newline at end of file -- cgit v1.2.3