summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PerfilRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PerfilRepository.cs')
-rw-r--r--Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PerfilRepository.cs191
1 files changed, 191 insertions, 0 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PerfilRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PerfilRepository.cs
new file mode 100644
index 0000000..67375a5
--- /dev/null
+++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PerfilRepository.cs
@@ -0,0 +1,191 @@
+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.Common;
+using Gestor.Model.Domain.Seguros;
+using NHibernate;
+using NHibernate.Connection;
+using NHibernate.Impl;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Runtime.CompilerServices;
+
+namespace Gestor.Infrastructure.Repository.Logic
+{
+ public class PerfilRepository : GenericRepository<PerfilDb>, IPerfilRepository, IGenericRepository<PerfilDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public PerfilRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public void Delete(long id)
+ {
+ PerfilDb perfilDb = base.FindEntityById(id);
+ if (perfilDb == null)
+ {
+ return;
+ }
+ base.Delete(perfilDb);
+ }
+
+ public Perfil Find(long id)
+ {
+ PerfilDb perfilDb = base.All().FirstOrDefault<PerfilDb>((PerfilDb x) => x.Id == id);
+ return ApplicationMapper.Mapper.Map<PerfilDb, Perfil>(perfilDb);
+ }
+
+ public List<Perfil> FindByControleId(long id)
+ {
+ List<PerfilDb> list = (
+ from x in base.All()
+ where x.Controle.Id == id
+ select x).ToList<PerfilDb>();
+ return ApplicationMapper.Mapper.Map<List<PerfilDb>, List<Perfil>>(list);
+ }
+
+ public List<Perfil> FindByControleIds(string ids)
+ {
+ object connection;
+ DataTable dataTable = new DataTable();
+ SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
+ if (sessionFactory != null)
+ {
+ connection = sessionFactory.ConnectionProvider.GetConnection();
+ }
+ else
+ {
+ connection = null;
+ }
+ using (SqlConnection sqlConnection = connection as SqlConnection)
+ {
+ using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
+ {
+ sqlCommand.CommandText = string.Concat("SELECT * FROM perfil WHERE idcontrole IN (", ids, ");");
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ if (dataTable.Rows.Count == 0)
+ {
+ return new List<Perfil>();
+ }
+ return dataTable.AsEnumerable().Select<DataRow, Perfil>((DataRow p) => {
+ GaragemTrabalhoEstudo? nullable;
+ bool? nullable1;
+ GaragemTrabalhoEstudo? nullable2;
+ GaragemTrabalhoEstudo? nullable3;
+ bool? nullable4;
+ bool? nullable5;
+ bool? nullable6;
+ Perfil perfil = new Perfil()
+ {
+ Cliente = new Cliente()
+ {
+ Id = long.Parse(p["idcliente"].ToString())
+ },
+ Controle = new Controle()
+ {
+ Id = long.Parse(p["idcontrole"].ToString())
+ },
+ Nome = p["nomecompleto"].ToString(),
+ Cpf = p["cpf"].ToString(),
+ Nascimento = (string.IsNullOrEmpty(p["datanascimento"].ToString()) ? null : new DateTime?(DateTime.Parse(p["datanascimento"].ToString()))),
+ EstadoCivil = (string.IsNullOrEmpty(p["estadocivil"].ToString()) ? null : new EstadoCivil?((EstadoCivil)int.Parse(p["estadocivil"].ToString()))),
+ Sexo = (string.IsNullOrEmpty(p["sexo"].ToString()) ? null : new Sexo?((Sexo)int.Parse(p["sexo"].ToString()))),
+ Relacao = (string.IsNullOrEmpty(p["relacao"].ToString()) ? null : new Relacao?((Relacao)int.Parse(p["relacao"].ToString()))),
+ Habilitacao = p["numerohabilitacao"].ToString(),
+ TempoHabilitacao = (string.IsNullOrEmpty(p["tempohabilitacao"].ToString()) ? null : new TempoHabilitacao?((TempoHabilitacao)int.Parse(p["tempohabilitacao"].ToString()))),
+ VeiculoResidencia = (string.IsNullOrEmpty(p["veiculosresidencia"].ToString()) ? null : new int?(int.Parse(p["veiculosresidencia"].ToString()))),
+ GaragemResidencia = (string.IsNullOrEmpty(p["garagemresidencia"].ToString()) ? null : new GaragemResidencia?((GaragemResidencia)int.Parse(p["garagemresidencia"].ToString())))
+ };
+ if (string.IsNullOrEmpty(p["garagemtrabalho"].ToString()))
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ else
+ {
+ nullable2 = new GaragemTrabalhoEstudo?((GaragemTrabalhoEstudo)int.Parse(p["garagemtrabalho"].ToString()));
+ }
+ perfil.GaragemTrabalho = nullable2;
+ if (string.IsNullOrEmpty(p["garagemestudo"].ToString()))
+ {
+ nullable = null;
+ nullable3 = nullable;
+ }
+ else
+ {
+ nullable3 = new GaragemTrabalhoEstudo?((GaragemTrabalhoEstudo)int.Parse(p["garagemestudo"].ToString()));
+ }
+ perfil.GaragemEstudo = nullable3;
+ perfil.TipoResidencia = (string.IsNullOrEmpty(p["tiporesidencia"].ToString()) ? null : new TipoResidencia?((TipoResidencia)int.Parse(p["tiporesidencia"].ToString())));
+ perfil.KmMensal = p["quilometragemmensal"].ToString();
+ perfil.DistanciaResidenciaTrabalho = (string.IsNullOrEmpty(p["distanciaresidenciatrabalho"].ToString()) ? null : new DistanciaTrabalho?((DistanciaTrabalho)int.Parse(p["distanciaresidenciatrabalho"].ToString())));
+ if (string.IsNullOrEmpty(p["usoprofissional"].ToString()))
+ {
+ nullable1 = null;
+ nullable4 = nullable1;
+ }
+ else
+ {
+ nullable4 = new bool?(p["usoprofissional"].ToString() == "1");
+ }
+ perfil.UsoProfissional = nullable4;
+ perfil.UsoDependentes = (string.IsNullOrEmpty(p["usodependentes"].ToString()) ? null : new UsoDependetes?((UsoDependetes)int.Parse(p["usodependentes"].ToString())));
+ perfil.Ocupacao = (string.IsNullOrEmpty(p["ocupacao"].ToString()) ? null : new Ocupacao?((Ocupacao)int.Parse(p["ocupacao"].ToString())));
+ if (string.IsNullOrEmpty(p["segurovida"].ToString()))
+ {
+ nullable1 = null;
+ nullable5 = nullable1;
+ }
+ else
+ {
+ nullable5 = new bool?(p["segurovida"].ToString() == "1");
+ }
+ perfil.SeguroVida = nullable5;
+ perfil.EstenderCobertura = (bool?)p["EstenderCobertura"];
+ if (string.IsNullOrEmpty(p["isencao"].ToString()))
+ {
+ nullable1 = null;
+ nullable6 = nullable1;
+ }
+ else
+ {
+ nullable6 = new bool?(p["isencao"].ToString() == "1");
+ }
+ perfil.Isencao = nullable6;
+ perfil.AntiFurto = (string.IsNullOrEmpty(p["antifurto"].ToString()) ? null : new Antifurto?((Antifurto)int.Parse(p["antifurto"].ToString())));
+ return perfil;
+ }).ToList<Perfil>();
+ }
+
+ public Perfil Merge(Perfil perfil)
+ {
+ PerfilDb perfilDb = ApplicationMapper.Mapper.Map<Perfil, PerfilDb>(perfil);
+ base.Merge(perfilDb);
+ return ApplicationMapper.Mapper.Map<PerfilDb, Perfil>(perfilDb);
+ }
+
+ public Perfil SaveOrUpdate(Perfil perfil)
+ {
+ PerfilDb perfilDb = ApplicationMapper.Mapper.Map<Perfil, PerfilDb>(perfil);
+ this.SaveOrUpdate(perfilDb);
+ return ApplicationMapper.Mapper.Map<PerfilDb, Perfil>(perfilDb);
+ }
+ }
+} \ No newline at end of file