diff options
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanosRepository.cs')
| -rw-r--r-- | Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanosRepository.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanosRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanosRepository.cs new file mode 100644 index 0000000..d76619d --- /dev/null +++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PlanosRepository.cs @@ -0,0 +1,101 @@ +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.Reflection;
+using System.Runtime.CompilerServices;
+
+namespace Gestor.Infrastructure.Repository.Logic
+{
+ public class PlanosRepository : GenericRepository<PlanosDb>, IPlanosRepository, IGenericRepository<PlanosDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public PlanosRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public List<Planos> Find(string description)
+ {
+ PlanosRepository.u003cu003ec__DisplayClass3_0 variable = null;
+ IQueryable<PlanosDb> planosDbs = base.All();
+ ParameterExpression parameterExpression = Expression.Parameter(typeof(PlanosDb), "x");
+ List<PlanosDb> list = planosDbs.Where<PlanosDb>(Expression.Lambda<Func<PlanosDb, bool>>(Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(PlanosDb).GetMethod("get_Descricao").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("ToUpper").MethodHandle), Array.Empty<Expression>()), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(PlanosRepository.u003cu003ec__DisplayClass3_0)), FieldInfo.GetFieldFromHandle(typeof(PlanosRepository.u003cu003ec__DisplayClass3_0).GetField("description").FieldHandle)) }), new ParameterExpression[] { parameterExpression })).ToList<PlanosDb>();
+ return ApplicationMapper.Mapper.Map<List<PlanosDb>, List<Planos>>(list);
+ }
+
+ public List<Planos> 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())
+ {
+ AuxiliarFinanceiro.Criar(sqlCommand);
+ sqlCommand.CommandText = "SELECT DISTINCT cs.idcplanos as id, cs.descricao as nome, cs.ativo, cs.idcplano, cs.idtipoconta, cs.ctipo, cp.descricao FROM cplanos cs INNER JOIN cplano cp ON cs.idcplano = cp.idcplano;";
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ return CustomMap.MapPlanos(dataTable);
+ }
+
+ public Planos FindById(long id)
+ {
+ PlanosDb planosDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<PlanosDb, Planos>(planosDb);
+ }
+
+ public List<Planos> FindByPlanoId(long id)
+ {
+ List<PlanosDb> list = (
+ from x in base.All()
+ where x.Plano.Id == id
+ select x).ToList<PlanosDb>();
+ return ApplicationMapper.Mapper.Map<List<PlanosDb>, List<Planos>>(list);
+ }
+
+ public Planos Merge(Planos planos)
+ {
+ PlanosDb planosDb = ApplicationMapper.Mapper.Map<Planos, PlanosDb>(planos);
+ base.Merge(planosDb);
+ return ApplicationMapper.Mapper.Map<PlanosDb, Planos>(planosDb);
+ }
+
+ public Planos SaveOrUpdate(Planos planos)
+ {
+ PlanosDb planosDb = ApplicationMapper.Mapper.Map<Planos, PlanosDb>(planos);
+ this.SaveOrUpdate(planosDb);
+ return ApplicationMapper.Mapper.Map<PlanosDb, Planos>(planosDb);
+ }
+ }
+}
\ No newline at end of file |