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, IAgendaRepository, IGenericRepository { 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 Find(string filter) { AgendaRepository.u003cu003ec__DisplayClass3_0 variable = null; IQueryable agendaDbs = base.All(); ParameterExpression parameterExpression = Expression.Parameter(typeof(AgendaDb), "x"); IQueryable agendaDbs1 = agendaDbs.Where(Expression.Lambda>(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()), (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(Expression.Lambda>(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(); } public List Find() { List list = base.All().ToList(); return ApplicationMapper.Mapper.Map, List>(list); } public Agenda FindById(long id) { AgendaDb agendaDb = base.FindEntityById(id); return ApplicationMapper.Mapper.Map(agendaDb); } public List FindByName(string name) { AgendaRepository.u003cu003ec__DisplayClass4_0 variable = null; IQueryable agendaDbs = base.All(); ParameterExpression parameterExpression = Expression.Parameter(typeof(AgendaDb), "x"); IQueryable agendaDbs1 = agendaDbs.Where(Expression.Lambda>(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()), (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(150); parameterExpression = Expression.Parameter(typeof(AgendaDb), "x"); return agendaDbs1.Select(Expression.Lambda>(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(); } public Agenda Merge(Agenda agenda) { AgendaDb agendaDb = ApplicationMapper.Mapper.Map(agenda); base.Merge(agendaDb); return ApplicationMapper.Mapper.Map(agendaDb); } public Agenda SaveOrUpdate(Agenda agenda) { AgendaDb agendaDb = ApplicationMapper.Mapper.Map(agenda); this.SaveOrUpdate(agendaDb); return ApplicationMapper.Mapper.Map(agendaDb); } } }