summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/CredencialRepository.cs
blob: 0e7d668987985dcf2aaf978b6574830fbba692ea (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
using AutoMapper;
using Gestor.Infrastructure.Entities.Ferramentas;
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 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 CredencialRepository : GenericRepository<CredencialDb>, ICredencialRepository, IGenericRepository<CredencialDb>
	{
		private readonly GenericUnitOfWork _unitOfWork;

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

		public void Delete(long id)
		{
			CredencialDb credencialDb = base.FindEntityById(id);
			if (credencialDb == null)
			{
				return;
			}
			credencialDb.Excluido = true;
			base.Merge(credencialDb);
		}

		public List<Credencial> Find(long idEmpresa)
		{
			List<CredencialDb> list = (
				from x in base.All()
				where x.IdEmpresa == idEmpresa && !x.Excluido
				select x).ToList<CredencialDb>();
			return ApplicationMapper.Mapper.Map<List<CredencialDb>, List<Credencial>>(list);
		}

		public List<Credencial> Find(string filter, long idEmpresa)
		{
			CredencialRepository.u003cu003ec__DisplayClass7_0 variable = null;
			IQueryable<CredencialDb> credencialDbs = base.All();
			ParameterExpression parameterExpression = Expression.Parameter(typeof(CredencialDb), "x");
			List<CredencialDb> list = credencialDbs.Where<CredencialDb>(Expression.Lambda<Func<CredencialDb, bool>>(Expression.AndAlso(Expression.Equal(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(CredencialDb).GetMethod("get_Excluido").MethodHandle)), Expression.Constant(false, typeof(bool))), Expression.OrElse(Expression.OrElse(Expression.AndAlso(Expression.Equal(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(CredencialDb).GetMethod("get_IdEmpresa").MethodHandle)), Expression.Field(Expression.Constant(variable, typeof(CredencialRepository.u003cu003ec__DisplayClass7_0)), FieldInfo.GetFieldFromHandle(typeof(CredencialRepository.u003cu003ec__DisplayClass7_0).GetField("idEmpresa").FieldHandle))), Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(CredencialDb).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(CredencialRepository.u003cu003ec__DisplayClass7_0)), FieldInfo.GetFieldFromHandle(typeof(CredencialRepository.u003cu003ec__DisplayClass7_0).GetField("filter").FieldHandle)) })), Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(CredencialDb).GetMethod("get_Email").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(CredencialRepository.u003cu003ec__DisplayClass7_0)), FieldInfo.GetFieldFromHandle(typeof(CredencialRepository.u003cu003ec__DisplayClass7_0).GetField("filter").FieldHandle)) })), Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(CredencialDb).GetMethod("get_Dominio").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(CredencialRepository.u003cu003ec__DisplayClass7_0)), FieldInfo.GetFieldFromHandle(typeof(CredencialRepository.u003cu003ec__DisplayClass7_0).GetField("filter").FieldHandle)) }))), new ParameterExpression[] { parameterExpression })).ToList<CredencialDb>();
			return ApplicationMapper.Mapper.Map<List<CredencialDb>, List<Credencial>>(list);
		}

		public Credencial FindById(long id)
		{
			CredencialDb credencialDb = base.FindEntityById(id);
			return ApplicationMapper.Mapper.Map<CredencialDb, Credencial>(credencialDb);
		}

		public Credencial Merge(Credencial credencial)
		{
			CredencialDb credencialDb = ApplicationMapper.Mapper.Map<Credencial, CredencialDb>(credencial);
			base.Merge(credencialDb);
			return ApplicationMapper.Mapper.Map<CredencialDb, Credencial>(credencialDb);
		}

		public Credencial SaveOrUpdate(Credencial credencial)
		{
			CredencialDb credencialDb = ApplicationMapper.Mapper.Map<Credencial, CredencialDb>(credencial);
			this.SaveOrUpdate(credencialDb);
			return ApplicationMapper.Mapper.Map<CredencialDb, Credencial>(credencialDb);
		}
	}
}