diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/MetaSeguradoraRepository.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/MetaSeguradoraRepository.cs')
| -rw-r--r-- | Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/MetaSeguradoraRepository.cs | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/MetaSeguradoraRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/MetaSeguradoraRepository.cs new file mode 100644 index 0000000..639e281 --- /dev/null +++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/MetaSeguradoraRepository.cs @@ -0,0 +1,127 @@ +using AutoMapper;
+using Gestor.Infrastructure.Entities.Generic;
+using Gestor.Infrastructure.Entities.Seguros;
+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.Generic;
+using Gestor.Model.Domain.Relatorios;
+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.Runtime.CompilerServices;
+
+namespace Gestor.Infrastructure.Repository.Logic
+{
+ public class MetaSeguradoraRepository : GenericRepository<MetaSeguradoraDb>, IMetaSeguradoraRepository, IGenericRepository<MetaSeguradoraDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public MetaSeguradoraRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public void Delete(long id)
+ {
+ base.Delete(base.FindEntityById(id));
+ }
+
+ public List<MetaSeguradora> Find(long id)
+ {
+ return (
+ from x in this._unitOfWork.Session.CreateQuery(string.Format("from MetaSeguradoraDb WHERE idciaseg = {0}", id)).List<MetaSeguradoraDb>()
+ select new MetaSeguradora()
+ {
+ Id = x.Id,
+ Mes = x.Mes,
+ Ano = x.Ano,
+ Valor = x.Valor
+ }).ToList<MetaSeguradora>();
+ }
+
+ public MetaSeguradora FindById(long id)
+ {
+ MetaSeguradoraDb metaSeguradoraDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<MetaSeguradoraDb, MetaSeguradora>(metaSeguradoraDb);
+ }
+
+ public List<MetaSeguradora> FindByMeta(Filtros filtro)
+ {
+ List<MetaSeguradora> metaSeguradoras;
+ object connection;
+ string str = (filtro.Seguradoras == null || filtro.Seguradoras.Count == 0 ? "" : string.Concat(" AND idciaseg IN (", string.Join<long>(",",
+ from v in filtro.Seguradoras
+ select v), ")"));
+ SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
+ DataTable dataTable = new DataTable();
+ if (sessionFactory != null)
+ {
+ connection = sessionFactory.ConnectionProvider.GetConnection();
+ }
+ else
+ {
+ connection = null;
+ }
+ using (SqlConnection sqlConnection = connection as SqlConnection)
+ {
+ using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
+ {
+ Auxiliar.CriarAuxiliar(sqlCommand, false);
+ object month = filtro.Fim.Month;
+ DateTime fim = filtro.Fim;
+ sqlCommand.CommandText = string.Format("SELECT IdMeta, IdCiaSeg, Mes, Ano, Valor\r\n FROM Meta\r\n WHERE (IdCiaSeg IS NOT NULL OR IdCiaSeg != '') AND Mes = {0} AND Ano = {1} {2};", month, fim.Year, str);
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ if (dataTable.Rows.Count != 0)
+ {
+ return (
+ from x in dataTable.AsEnumerable().ToList<DataRow>()
+ select new MetaSeguradora()
+ {
+ Id = x.Field<long>("IdMeta"),
+ Mes = (Mes)x.Field<int>("Mes"),
+ Ano = long.Parse(x.Field<object>("Ano").ToString()),
+ Valor = x.Field<decimal>("Valor"),
+ Seguradora = Auxiliar.Seguradoras.FirstOrDefault<Seguradora>((Seguradora s) => s.Id == x.Field<long>("IdCiaseg"))
+ }).ToList<MetaSeguradora>();
+ }
+ else
+ {
+ metaSeguradoras = new List<MetaSeguradora>();
+ }
+ }
+ }
+ return metaSeguradoras;
+ }
+
+ public MetaSeguradora Merge(MetaSeguradora metaSeguradora)
+ {
+ MetaSeguradoraDb idAggilizador = ApplicationMapper.Mapper.Map<MetaSeguradora, MetaSeguradoraDb>(metaSeguradora);
+ idAggilizador.IdAggilizador = idAggilizador.Seguradora.IdAggilizador;
+ base.Merge(idAggilizador);
+ return ApplicationMapper.Mapper.Map<MetaSeguradoraDb, MetaSeguradora>(idAggilizador);
+ }
+
+ public MetaSeguradora SaveOrUpdate(MetaSeguradora metaSeguradora)
+ {
+ MetaSeguradoraDb idAggilizador = ApplicationMapper.Mapper.Map<MetaSeguradora, MetaSeguradoraDb>(metaSeguradora);
+ idAggilizador.IdAggilizador = idAggilizador.Seguradora.IdAggilizador;
+ this.SaveOrUpdate(idAggilizador);
+ return ApplicationMapper.Mapper.Map<MetaSeguradoraDb, MetaSeguradora>(idAggilizador);
+ }
+ }
+}
\ No newline at end of file |