using AutoMapper; using Gestor.Infrastructure.Entities.Relatorios; using Gestor.Infrastructure.Helpers; using Gestor.Infrastructure.Mappers; using Gestor.Infrastructure.Repository.Generic; using Gestor.Infrastructure.Repository.Interface; using Gestor.Infrastructure.UnitOfWork.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Relatorios; using System; using System.Collections.Generic; namespace Gestor.Infrastructure.Repository.Logic { public class ParametrosRelatorioRepository : GenericRepository, IParametrosRelatorioRepository, IGenericRepository { private readonly GenericUnitOfWork _unitOfWork; public ParametrosRelatorioRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session) { this._unitOfWork = unitOfWork; } public void Delete(long id) { ParametrosRelatorioDb parametrosRelatorioDb = base.FindEntityById(id); if (parametrosRelatorioDb == null) { return; } base.Delete(parametrosRelatorioDb); } public List Find(long id, Relatorio relatorio) { List parametrosRelatorios = this.Select(new List() { new Condicao() { Campo = "IdUsuario", Valores = id.CriarValor() }, new Condicao() { Campo = "Relatorio", Valores = relatorio.CriarValor() }, new Condicao() { Campo = "Header", Valores = null, Operador = Operador.Diferente }, new Condicao() { Campo = "Header", Valores = "".CriarValor(), Operador = Operador.Diferente } }); if (parametrosRelatorios.Count == 0) { parametrosRelatorios = this.Select(new List() { new Condicao() { Campo = "IdUsuario", Valores = 0.CriarValor() }, new Condicao() { Campo = "Relatorio", Valores = relatorio.CriarValor() }, new Condicao() { Campo = "Header", Valores = null, Operador = Operador.Diferente }, new Condicao() { Campo = "Header", Valores = "".CriarValor(), Operador = Operador.Diferente } }); } return parametrosRelatorios; } public ParametrosRelatorio Merge(ParametrosRelatorio parametrosRelatorio) { ParametrosRelatorioDb parametrosRelatorioDb = ApplicationMapper.Mapper.Map(parametrosRelatorio); base.Merge(parametrosRelatorioDb); return ApplicationMapper.Mapper.Map(parametrosRelatorioDb); } public ParametrosRelatorio SaveOrUpdate(ParametrosRelatorio parametrosRelatorio) { ParametrosRelatorioDb parametrosRelatorioDb = ApplicationMapper.Mapper.Map(parametrosRelatorio); this.SaveOrUpdate(parametrosRelatorioDb); return ApplicationMapper.Mapper.Map(parametrosRelatorioDb); } public List Select(List condicao) { return this._unitOfWork.Select(condicao.CreateParameters(0), "SELECT * FROM CamposRelatorios WHERE ", "").MapCamposRelatorio(); } } }