summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs')
-rw-r--r--Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs
new file mode 100644
index 0000000..1ab42b8
--- /dev/null
+++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AgendaRepository.cs
@@ -0,0 +1,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);
+ }
+ }
+} \ No newline at end of file