1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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<PlanoDb>, IPlanoRepository, IGenericRepository<PlanoDb>
{
private readonly GenericUnitOfWork _unitOfWork;
public PlanoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
{
this._unitOfWork = unitOfWork;
}
public List<Plano> Find(string filter)
{
PlanoRepository.u003cu003ec__DisplayClass2_0 variable = null;
IQueryable<PlanoDb> planoDbs = base.All();
ParameterExpression parameterExpression = Expression.Parameter(typeof(PlanoDb), "x");
IQueryable<PlanoDb> planoDbs1 = planoDbs.Where<PlanoDb>(Expression.Lambda<Func<PlanoDb, bool>>(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<Expression>()), (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<PlanoDb, Plano>(Expression.Lambda<Func<PlanoDb, Plano>>(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<Plano>();
}
public List<Plano> 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<DataRow>()
select new Plano()
{
Id = a.Field<long>("id"),
Descricao = a.Field<string>("nome"),
Ativo = (a.Field<object>("ativo") == null ? true : a.Field<object>("ativo").ToString() == "1")
}).ToList<Plano>();
}
public Plano Merge(Plano plano)
{
PlanoDb planoDb = ApplicationMapper.Mapper.Map<Plano, PlanoDb>(plano);
base.Merge(planoDb);
return ApplicationMapper.Mapper.Map<PlanoDb, Plano>(planoDb);
}
public Plano SaveOrUpdate(Plano plano)
{
PlanoDb planoDb = ApplicationMapper.Mapper.Map<Plano, PlanoDb>(plano);
this.SaveOrUpdate(planoDb);
return ApplicationMapper.Mapper.Map<PlanoDb, Plano>(planoDb);
}
}
}
|