using AutoMapper; using Gestor.Infrastructure.Entities.Generic; using Gestor.Infrastructure.Entities.Seguros; using Gestor.Infrastructure.Mappers; using Gestor.Infrastructure.Repository.Generic; using Gestor.Infrastructure.Repository.Interface; using Gestor.Infrastructure.UnitOfWork.Generic; using Gestor.Model.Domain.Seguros; using NHibernate; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; namespace Gestor.Infrastructure.Repository.Logic { public class ConfigExtratoImportRepository : GenericRepository, IConfigExtratoImportRepository, IGenericRepository { private readonly GenericUnitOfWork _unitOfWork; public ConfigExtratoImportRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) { this._unitOfWork = unitOfWork; } public void Delete(long id) { base.Delete(base.FindEntityById(id)); } public List Find(bool ativo) { return ( from x in this._unitOfWork.Session.CreateQuery("from ConfigExtratoImportDb \r\n where ativo IS NULL OR ativo != '1'").List() select new ConfigExtratoImport() { Id = x.Id, IdSeguradora = x.IdSeguradora, Codigo = x.Codigo, Descricao = x.Descricao, Ativo = x.Ativo }).ToList(); } public List Find() { return ( from x in this._unitOfWork.Session.CreateQuery("from ConfigExtratoImportDb").List() select new ConfigExtratoImport() { Id = x.Id, IdSeguradora = x.IdSeguradora, Codigo = x.Codigo, Descricao = x.Descricao, Ativo = x.Ativo }).ToList(); } public ConfigExtratoImport FindById(long id) { ConfigExtratoImportDb configExtratoImportDb = base.FindEntityById(id); return ApplicationMapper.Mapper.Map(configExtratoImportDb); } public List FindBySeguradora(long id) { return ( from x in this._unitOfWork.Session.CreateQuery(string.Format("from ConfigExtratoImportDb where IdSeguradora = {0}", id)).List() select new ConfigExtratoImport() { Id = x.Id, IdSeguradora = x.IdSeguradora, Codigo = x.Codigo, Descricao = x.Descricao, Ativo = x.Ativo }).ToList(); } public Gestor.Model.Domain.Seguros.ConfigExtratoImport Merge(Gestor.Model.Domain.Seguros.ConfigExtratoImport ConfigExtratoImport) { ConfigExtratoImportDb configExtratoImportDb = ApplicationMapper.Mapper.Map(ConfigExtratoImport); base.Merge(configExtratoImportDb); return ApplicationMapper.Mapper.Map(configExtratoImportDb); } public List MergeRange(List configExtratoImport) { List configExtratoImportDbs = ApplicationMapper.Mapper.Map, List>(configExtratoImport); ConfigExtratoImportRepository configExtratoImportRepository = this; configExtratoImportDbs.ForEach(new Action(configExtratoImportRepository.Merge)); return ApplicationMapper.Mapper.Map, List>(configExtratoImportDbs); } public Gestor.Model.Domain.Seguros.ConfigExtratoImport SaveOrUpdate(Gestor.Model.Domain.Seguros.ConfigExtratoImport ConfigExtratoImport) { ConfigExtratoImportDb configExtratoImportDb = ApplicationMapper.Mapper.Map(ConfigExtratoImport); this.SaveOrUpdate(configExtratoImportDb); return ApplicationMapper.Mapper.Map(configExtratoImportDb); } } }