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 RamoRepository : GenericRepository, IRamoRepository, IGenericRepository { private readonly GenericUnitOfWork _unitOfWork; public RamoRepository(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 RamoDb \r\n where ativo IS NULL OR ativo != '1'").List() select new Ramo() { Id = x.Id, Nome = x.Nome, Iof = x.Iof, Ativo = x.Ativo }).ToList(); } public List Find() { return ( from x in this._unitOfWork.Session.CreateQuery("from RamoDb").List() select new Ramo() { Id = x.Id, Nome = x.Nome, Iof = x.Iof, Ativo = x.Ativo }).ToList(); } public Ramo FindById(long id) { RamoDb ramoDb = base.FindEntityById(id); return ApplicationMapper.Mapper.Map(ramoDb); } public Ramo Merge(Ramo ramo) { RamoDb ramoDb = ApplicationMapper.Mapper.Map(ramo); base.Merge(ramoDb); return ApplicationMapper.Mapper.Map(ramoDb); } public List MergeRange(List ramos) { List ramoDbs = ApplicationMapper.Mapper.Map, List>(ramos); RamoRepository ramoRepository = this; ramoDbs.ForEach(new Action(ramoRepository.Merge)); return ApplicationMapper.Mapper.Map, List>(ramoDbs); } public Ramo SaveOrUpdate(Ramo ramo) { RamoDb ramoDb = ApplicationMapper.Mapper.Map(ramo); this.SaveOrUpdate(ramoDb); return ApplicationMapper.Mapper.Map(ramoDb); } } }