summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/BancoRepository.cs
blob: eaba0c11687d03fbef1712ae34eb6aa4494d65ae (plain)
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
using AutoMapper;
using Gestor.Infrastructure.Entities.Common;
using Gestor.Infrastructure.Mappers;
using Gestor.Infrastructure.Repository.Generic;
using Gestor.Infrastructure.Repository.Interface;
using Gestor.Infrastructure.UnitOfWork.Generic;
using Gestor.Model.Domain.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Gestor.Infrastructure.Repository.Logic
{
	public class BancoRepository : GenericRepository<BancoDb>, IBancoRepository, IGenericRepository<BancoDb>
	{
		private readonly GenericUnitOfWork _unitOfWork;

		public BancoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
		{
			this._unitOfWork = unitOfWork;
		}

		public void Delete(long id)
		{
			base.Delete(base.FindEntityById(id));
		}

		public List<Banco> Find(string filter)
		{
			BancoRepository.u003cu003ec__DisplayClass7_0 variable = null;
			IQueryable<BancoDb> bancoDbs = base.All();
			ParameterExpression parameterExpression = Expression.Parameter(typeof(BancoDb), "x");
			IQueryable<BancoDb> bancoDbs1 = bancoDbs.Where<BancoDb>(Expression.Lambda<Func<BancoDb, bool>>(Expression.OrElse(Expression.Call(Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(BancoDb).GetMethod("get_Nome").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Trim").MethodHandle), Array.Empty<Expression>()), (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(BancoRepository.u003cu003ec__DisplayClass7_0)), FieldInfo.GetFieldFromHandle(typeof(BancoRepository.u003cu003ec__DisplayClass7_0).GetField("filter").FieldHandle)) }), Expression.Call(Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(BancoDb).GetMethod("get_Codigo").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(int).GetMethod("ToString").MethodHandle), Array.Empty<Expression>()), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Trim").MethodHandle), Array.Empty<Expression>()), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(BancoRepository.u003cu003ec__DisplayClass7_0)), FieldInfo.GetFieldFromHandle(typeof(BancoRepository.u003cu003ec__DisplayClass7_0).GetField("filter").FieldHandle)) })), new ParameterExpression[] { parameterExpression }));
			parameterExpression = Expression.Parameter(typeof(BancoDb), "x");
			return bancoDbs1.Select<BancoDb, Banco>(Expression.Lambda<Func<BancoDb, Banco>>(Expression.MemberInit(Expression.New(typeof(Banco)), new MemberBinding[] { Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Banco).GetMethod("set_Id", new Type[] { typeof(int) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(BancoDb).GetMethod("get_Id").MethodHandle))), Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Banco).GetMethod("set_Nome", new Type[] { typeof(string) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(BancoDb).GetMethod("get_Nome").MethodHandle))), Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Banco).GetMethod("set_Codigo", new Type[] { typeof(int) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(BancoDb).GetMethod("get_Codigo").MethodHandle))) }), new ParameterExpression[] { parameterExpression })).ToList<Banco>();
		}

		public Banco FindById(long id)
		{
			BancoDb bancoDb = base.FindEntityById(id);
			return ApplicationMapper.Mapper.Map<BancoDb, Banco>(bancoDb);
		}

		public Banco Merge(Banco banco)
		{
			BancoDb bancoDb = ApplicationMapper.Mapper.Map<Banco, BancoDb>(banco);
			base.Merge(bancoDb);
			return ApplicationMapper.Mapper.Map<BancoDb, Banco>(bancoDb);
		}

		public Banco SaveOrUpdate(Banco banco)
		{
			BancoDb bancoDb = ApplicationMapper.Mapper.Map<Banco, BancoDb>(banco);
			this.SaveOrUpdate(bancoDb);
			return ApplicationMapper.Mapper.Map<BancoDb, Banco>(bancoDb);
		}

		public List<Banco> SelectDefault()
		{
			return ApplicationMapper.Mapper.Map<List<BancoDb>, List<Banco>>((
				from x in base.All()
				orderby x.Nome
				select x).ToList<BancoDb>());
		}
	}
}