summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs')
-rw-r--r--Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs152
1 files changed, 152 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs
new file mode 100644
index 0000000..4a0f512
--- /dev/null
+++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/TitularesVidaRepository.cs
@@ -0,0 +1,152 @@
+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 TitularesVidaRepository : GenericRepository<TitularesVidaDb>, ITitularesVidaRepository, IGenericRepository<TitularesVidaDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public TitularesVidaRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public void Delete(long id)
+ {
+ base.Delete(base.FindEntityById(id));
+ }
+
+ public void DeleteRange(List<long> ids)
+ {
+ for (int i = 0; i < ids.Count; i += 200)
+ {
+ IEnumerable<long> nums = ids.Skip<long>(i).Take<long>(200);
+ List<TitularesVidaDb> list = (
+ from x in base.All()
+ where nums.Contains<long>(x.Id)
+ select x).ToList<TitularesVidaDb>();
+ base.DeleteRange(list);
+ }
+ }
+
+ public List<TitularesVida> Find(long id)
+ {
+ 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)
+ {
+ if (sqlConnection != null)
+ {
+ using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
+ {
+ sqlCommand.CommandText = string.Format("SELECT * FROM TitularesVida WHERE IdItem = {0}", id);
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ }
+ return dataTable.AsEnumerable().ToList<DataRow>().Select<DataRow, TitularesVida>((DataRow x) => {
+ DateTime? nullable;
+ DateTime? nullable1;
+ DateTime? nullable2;
+ DateTime? nullable3;
+ TitularesVida titularesVida = new TitularesVida()
+ {
+ Id = x.Field<long>("Id"),
+ Codigo = (x.Field<object>("Codigo") != null ? x.Field<object>("Codigo").ToString() : null)
+ };
+ if (x.Field<object>("Inicio") != null)
+ {
+ nullable1 = new DateTime?(DateTime.Parse(x.Field<object>("Inicio").ToString()));
+ }
+ else
+ {
+ nullable = null;
+ nullable1 = nullable;
+ }
+ titularesVida.Inicio = nullable1;
+ if (x.Field<object>("Fim") != null)
+ {
+ nullable2 = new DateTime?(DateTime.Parse(x.Field<object>("Fim").ToString()));
+ }
+ else
+ {
+ nullable = null;
+ nullable2 = nullable;
+ }
+ titularesVida.Fim = nullable2;
+ titularesVida.Fatura = (x.Field<object>("Fatura") != null ? x.Field<object>("Fatura").ToString() : null);
+ titularesVida.Nome = (x.Field<object>("Nome") != null ? x.Field<object>("Nome").ToString() : null);
+ titularesVida.Observacao = (x.Field<object>("Observacao") != null ? x.Field<object>("Observacao").ToString() : null);
+ if (x.Field<object>("Nascimento") != null)
+ {
+ nullable3 = new DateTime?(DateTime.Parse(x.Field<object>("Nascimento").ToString()));
+ }
+ else
+ {
+ nullable = null;
+ nullable3 = nullable;
+ }
+ titularesVida.Nascimento = nullable3;
+ titularesVida.Cpf = (x.Field<object>("Cpf") != null ? x.Field<object>("Cpf").ToString() : null);
+ titularesVida.Matricula = (x.Field<object>("Matricula") != null ? x.Field<object>("Matricula").ToString() : null);
+ titularesVida.Premio = new decimal?((x.Field<object>("Premio") != null ? x.Field<decimal>("Premio") : decimal.Zero));
+ titularesVida.Capital = new decimal?((x.Field<object>("Capital") != null ? x.Field<decimal>("Capital") : decimal.Zero));
+ titularesVida.Tipo = (x.Field<object>("Tipo") != null ? (TipoTitular?)Enum.Parse(typeof(TipoTitular), x.Field<object>("Tipo").ToString()) : null);
+ titularesVida.Dependente = (x.Field<object>("Dependente_id") != null ? this.FindById(x.Field<long>("Dependente_id")) : null);
+ return titularesVida;
+ }).ToList<TitularesVida>();
+ }
+
+ public TitularesVida FindById(long id)
+ {
+ TitularesVidaDb titularesVidaDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<TitularesVidaDb, TitularesVida>(titularesVidaDb);
+ }
+
+ public TitularesVida Merge(TitularesVida vida)
+ {
+ TitularesVidaDb titularesVidaDb = ApplicationMapper.Mapper.Map<TitularesVida, TitularesVidaDb>(vida);
+ base.Merge(titularesVidaDb);
+ return ApplicationMapper.Mapper.Map<TitularesVidaDb, TitularesVida>(titularesVidaDb);
+ }
+
+ public TitularesVida SaveOrUpdate(TitularesVida vida)
+ {
+ TitularesVidaDb titularesVidaDb = ApplicationMapper.Mapper.Map<TitularesVida, TitularesVidaDb>(vida);
+ this.SaveOrUpdate(titularesVidaDb);
+ return ApplicationMapper.Mapper.Map<TitularesVidaDb, TitularesVida>(titularesVidaDb);
+ }
+ }
+} \ No newline at end of file