summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PermissaoUsuarioRepository.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/PermissaoUsuarioRepository.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PermissaoUsuarioRepository.cs')
-rw-r--r--Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PermissaoUsuarioRepository.cs84
1 files changed, 84 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PermissaoUsuarioRepository.cs b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PermissaoUsuarioRepository.cs
new file mode 100644
index 0000000..e0e226c
--- /dev/null
+++ b/Codemerx/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/PermissaoUsuarioRepository.cs
@@ -0,0 +1,84 @@
+using AutoMapper;
+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.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;
+
+namespace Gestor.Infrastructure.Repository.Logic
+{
+ public class PermissaoUsuarioRepository : GenericRepository<PermissaoUsuarioDb>, IPermissaoUsuarioRepository
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public PermissaoUsuarioRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public PermissaoUsuario FindByPermissao(long id, TipoTela tela)
+ {
+ return this.Select(string.Format(" AND IdUsuario = {0} AND Tela = {1}", id, (int)tela)).FirstOrDefault<PermissaoUsuario>();
+ }
+
+ public List<PermissaoUsuario> FindByUsuario(long id)
+ {
+ return this.Select(string.Format(" AND IdUsuario = {0}", id));
+ }
+
+ public PermissaoUsuario Merge(PermissaoUsuario permissao)
+ {
+ PermissaoUsuarioDb permissaoUsuarioDb = ApplicationMapper.Mapper.Map<PermissaoUsuario, PermissaoUsuarioDb>(permissao);
+ base.Merge(permissaoUsuarioDb);
+ return ApplicationMapper.Mapper.Map<PermissaoUsuarioDb, PermissaoUsuario>(permissaoUsuarioDb);
+ }
+
+ public PermissaoUsuario SaveOrUpdate(PermissaoUsuario permissao)
+ {
+ PermissaoUsuarioDb permissaoUsuarioDb = ApplicationMapper.Mapper.Map<PermissaoUsuario, PermissaoUsuarioDb>(permissao);
+ this.SaveOrUpdate(permissaoUsuarioDb);
+ return ApplicationMapper.Mapper.Map<PermissaoUsuarioDb, PermissaoUsuario>(permissaoUsuarioDb);
+ }
+
+ private List<PermissaoUsuario> Select(string condition)
+ {
+ 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())
+ {
+ Auxiliar.CriarAuxiliarUsuario(sqlCommand);
+ sqlCommand.CommandText = string.Concat("SELECT DISTINCT * FROM PermissaoUsuario WHERE 1=1 ", condition, ";");
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ return dataTable.MapPermissao();
+ }
+ }
+} \ No newline at end of file