summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/EmpresaRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/EmpresaRepository.cs')
-rw-r--r--Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/EmpresaRepository.cs143
1 files changed, 143 insertions, 0 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/EmpresaRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/EmpresaRepository.cs
new file mode 100644
index 0000000..4d51e87
--- /dev/null
+++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/EmpresaRepository.cs
@@ -0,0 +1,143 @@
+using AutoMapper;
+using Gestor.Infrastructure.Entities.Common;
+using Gestor.Infrastructure.Entities.Generic;
+using Gestor.Infrastructure.Mappers;
+using Gestor.Infrastructure.Repository.Generic;
+using Gestor.Infrastructure.Repository.Interface;
+using Gestor.Infrastructure.UnitOfWork.Generic;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Seguros;
+using NHibernate;
+using NHibernate.Connection;
+using NHibernate.Impl;
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+namespace Gestor.Infrastructure.Repository.Logic
+{
+ public class EmpresaRepository : GenericRepository<EmpresaDb>, IEmpresaRepository, IGenericRepository<EmpresaDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public EmpresaRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public string BuscarSenhaAdm(long idempresa = 1L)
+ {
+ EmpresaDb empresaDb = base.All().FirstOrDefault<EmpresaDb>((EmpresaDb x) => x.Id == idempresa);
+ if (empresaDb != null)
+ {
+ return empresaDb.SenhaAdmin;
+ }
+ return null;
+ }
+
+ public double ConsultaEspacoBancoInGb()
+ {
+ double num;
+ object connection;
+ using (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 = "EXEC sp_spaceused @oneresultset = '1'";
+ SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
+ if (!sqlDataReader.HasRows)
+ {
+ return 0;
+ }
+ else
+ {
+ sqlDataReader.Read();
+ double num1 = double.Parse(sqlDataReader["reserved"].ToString().Replace("KB", string.Empty).Trim());
+ double num2 = double.Parse(sqlDataReader["unallocated space"].ToString().Replace("MB", string.Empty).Replace(".", ",").Trim());
+ num = (num1 / 1024 + num2) / 1024;
+ }
+ }
+ }
+ }
+ return num;
+ }
+
+ public void Delete(long id)
+ {
+ base.Delete(base.FindEntityById(id));
+ }
+
+ public List<Empresa> Find(long idempresa = 0L)
+ {
+ return (
+ from x in (idempresa == 0 ? base.All() :
+ from x in base.All()
+ where x.Id == idempresa
+ select x)
+ select new Empresa()
+ {
+ Id = x.Id,
+ Nome = x.Nome,
+ Documento = x.Documento,
+ Serial = x.Serial
+ }).ToList<Empresa>();
+ }
+
+ public List<Cliente> FindAsCliente(string filter)
+ {
+ EmpresaRepository.u003cu003ec__DisplayClass9_0 variable = null;
+ IQueryable<EmpresaDb> empresaDbs = base.All();
+ ParameterExpression parameterExpression = Expression.Parameter(typeof(EmpresaDb), "x");
+ IQueryable<EmpresaDb> empresaDbs1 = empresaDbs.Where<EmpresaDb>(Expression.Lambda<Func<EmpresaDb, bool>>(Expression.OrElse(Expression.OrElse(Expression.Call(Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EmpresaDb).GetMethod("get_Nome").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("ToUpper").MethodHandle), Array.Empty<Expression>()), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(EmpresaRepository.u003cu003ec__DisplayClass9_0)), FieldInfo.GetFieldFromHandle(typeof(EmpresaRepository.u003cu003ec__DisplayClass9_0).GetField("filter").FieldHandle)) }), Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EmpresaDb).GetMethod("get_Documento").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(EmpresaRepository.u003cu003ec__DisplayClass9_0)), FieldInfo.GetFieldFromHandle(typeof(EmpresaRepository.u003cu003ec__DisplayClass9_0).GetField("filter").FieldHandle)) })), Expression.Call(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EmpresaDb).GetMethod("get_Serial").MethodHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(string).GetMethod("Contains", new Type[] { typeof(string) }).MethodHandle), new Expression[] { Expression.Field(Expression.Constant(variable, typeof(EmpresaRepository.u003cu003ec__DisplayClass9_0)), FieldInfo.GetFieldFromHandle(typeof(EmpresaRepository.u003cu003ec__DisplayClass9_0).GetField("filter").FieldHandle)) })), new ParameterExpression[] { parameterExpression }));
+ parameterExpression = Expression.Parameter(typeof(EmpresaDb), "x");
+ return empresaDbs1.Select<EmpresaDb, Cliente>(Expression.Lambda<Func<EmpresaDb, Cliente>>(Expression.MemberInit(Expression.New(typeof(Cliente)), new MemberBinding[] { Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(DomainBase).GetMethod("set_Id", new Type[] { typeof(long) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EntityBase).GetMethod("get_Id").MethodHandle))), Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Cliente).GetMethod("set_Nome", new Type[] { typeof(string) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EmpresaDb).GetMethod("get_Nome").MethodHandle))), Expression.Bind((MethodInfo)MethodBase.GetMethodFromHandle(typeof(Cliente).GetMethod("set_Documento", new Type[] { typeof(string) }).MethodHandle), Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(EmpresaDb).GetMethod("get_Documento").MethodHandle))) }), new ParameterExpression[] { parameterExpression })).ToList<Cliente>();
+ }
+
+ public Empresa FindByDocumento(string documento)
+ {
+ EmpresaDb empresaDb = base.All().FirstOrDefault<EmpresaDb>((EmpresaDb e) => e.Documento.Replace(",", string.Empty).Replace(".", string.Empty).Replace("-", string.Empty).Replace("/", string.Empty).Equals(documento)) ?? base.All().First<EmpresaDb>();
+ return ApplicationMapper.Mapper.Map<EmpresaDb, Empresa>(empresaDb);
+ }
+
+ public Empresa FindById(long id)
+ {
+ EmpresaDb empresaDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<EmpresaDb, Empresa>(empresaDb);
+ }
+
+ public Empresa FindBySerial(string serial)
+ {
+ EmpresaDb empresaDb = base.All().FirstOrDefault<EmpresaDb>((EmpresaDb e) => e.Serial.Equals(serial)) ?? base.All().First<EmpresaDb>();
+ return ApplicationMapper.Mapper.Map<EmpresaDb, Empresa>(empresaDb);
+ }
+
+ public Empresa Merge(Empresa empresa)
+ {
+ EmpresaDb empresaDb = ApplicationMapper.Mapper.Map<Empresa, EmpresaDb>(empresa);
+ base.Merge(empresaDb);
+ return ApplicationMapper.Mapper.Map<EmpresaDb, Empresa>(empresaDb);
+ }
+
+ public Empresa SaveOrUpdate(Empresa empresa)
+ {
+ EmpresaDb empresaDb = ApplicationMapper.Mapper.Map<Empresa, EmpresaDb>(empresa);
+ this.SaveOrUpdate(empresaDb);
+ return ApplicationMapper.Mapper.Map<EmpresaDb, Empresa>(empresaDb);
+ }
+ }
+} \ No newline at end of file