summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs
blob: 1ab42b86c80e35802c84d604eb46639bce048285 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using AutoMapper;
using Gestor.Infrastructure.Entities.Ferramentas;
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.Ferramentas;
using Gestor.Model.Domain.Generic;
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 AgendaRepository : GenericRepository<AgendaDb>, IAgendaRepository, IGenericRepository<AgendaDb>
	{
		private readonly GenericUnitOfWork _unitOfWork;

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

		public void Delete(long id)
		{
			AgendaDb agendaDb = base.FindEntityById(id);
			if (agendaDb == null)
			{
				return;
			}
			(new AgendaEmailRepository(this._unitOfWork)).DeleteRange(id);
			(new AgendaTelefoneRepository(this._unitOfWork)).DeleteRange(id);
			base.Delete(agendaDb);
		}

		public List<Agenda> Find(string filter)
		{
			AgendaRepository.u003cu003ec__DisplayClass3_0 variable = null;
			IQueryable<AgendaDb> agendaDbs = base.All();
			ParameterExpression parameterExpression = Expression.Parameter(typeof(AgendaDb), "x");
			IQueryable<AgendaDb> agendaDbs1 = agendaDbs.Where<AgendaDb>(Expression.Lambda<Func<AgendaDb, bool>>(Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(AgendaDb).GetMethod("get_Nome").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(AgendaRepository.u003cu003ec__DisplayClass3_0)), FieldInfo.GetFieldFromHandle(typeof(AgendaRepository.u003cu003ec__DisplayClass3_0).GetField("filter").FieldHandle)) }), new ParameterExpression[] { parameterExpression }));
			parameterExpression = Expression.Parameter(typeof(AgendaDb), "x");
			return agendaDbs1.Select<AgendaDb, Agenda>(Expression.Lambda<Func<AgendaDb, Agenda>>(Expression.MemberInit(Expression.New(typeof(Agenda)), 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(Agenda).GetMethod("set_Nome", new Type[] { typeof(string) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(AgendaDb).GetMethod("get_Nome").MethodHandle))) }), new ParameterExpression[] { parameterExpression })).ToList<Agenda>();
		}

		public List<Agenda> Find()
		{
			List<AgendaDb> list = base.All().ToList<AgendaDb>();
			return ApplicationMapper.Mapper.Map<List<AgendaDb>, List<Agenda>>(list);
		}

		public Agenda FindById(long id)
		{
			AgendaDb agendaDb = base.FindEntityById(id);
			return ApplicationMapper.Mapper.Map<AgendaDb, Agenda>(agendaDb);
		}

		public List<Agenda> FindByName(string name)
		{
			AgendaRepository.u003cu003ec__DisplayClass4_0 variable = null;
			IQueryable<AgendaDb> agendaDbs = base.All();
			ParameterExpression parameterExpression = Expression.Parameter(typeof(AgendaDb), "x");
			IQueryable<AgendaDb> agendaDbs1 = agendaDbs.Where<AgendaDb>(Expression.Lambda<Func<AgendaDb, bool>>(Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(AgendaDb).GetMethod("get_Nome").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(AgendaRepository.u003cu003ec__DisplayClass4_0)), FieldInfo.GetFieldFromHandle(typeof(AgendaRepository.u003cu003ec__DisplayClass4_0).GetField("name").FieldHandle)) }), new ParameterExpression[] { parameterExpression })).Take<AgendaDb>(150);
			parameterExpression = Expression.Parameter(typeof(AgendaDb), "x");
			return agendaDbs1.Select<AgendaDb, Agenda>(Expression.Lambda<Func<AgendaDb, Agenda>>(Expression.MemberInit(Expression.New(typeof(Agenda)), 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(Agenda).GetMethod("set_Nome", new Type[] { typeof(string) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(AgendaDb).GetMethod("get_Nome").MethodHandle))) }), new ParameterExpression[] { parameterExpression })).ToList<Agenda>();
		}

		public Agenda Merge(Agenda agenda)
		{
			AgendaDb agendaDb = ApplicationMapper.Mapper.Map<Agenda, AgendaDb>(agenda);
			base.Merge(agendaDb);
			return ApplicationMapper.Mapper.Map<AgendaDb, Agenda>(agendaDb);
		}

		public Agenda SaveOrUpdate(Agenda agenda)
		{
			AgendaDb agendaDb = ApplicationMapper.Mapper.Map<Agenda, AgendaDb>(agenda);
			this.SaveOrUpdate(agendaDb);
			return ApplicationMapper.Mapper.Map<AgendaDb, Agenda>(agendaDb);
		}
	}
}