diff options
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RepasseRepository.cs')
| -rw-r--r-- | Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RepasseRepository.cs | 298 |
1 files changed, 0 insertions, 298 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RepasseRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RepasseRepository.cs deleted file mode 100644 index 861ac85..0000000 --- a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/RepasseRepository.cs +++ /dev/null @@ -1,298 +0,0 @@ -using AutoMapper;
-using Gestor.Infrastructure.Entities.Ferramentas;
-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.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 RepasseRepository : GenericRepository<RepasseDb>, IRepasseRepository, IGenericRepository<RepasseDb>
- {
- private readonly GenericUnitOfWork _unitOfWork;
-
- public RepasseRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
- {
- this._unitOfWork = unitOfWork;
- }
-
- public List<Repasse> DefaultSelect(long idempresa = 0L)
- {
- List<Repasse> repasses;
- object connection;
- List<long> nums = null;
- Func<DataRow, VinculoRepasse> func1 = null;
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- DataTable dataTable = new DataTable();
- DataTable dataTable1 = new DataTable();
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- Auxiliar.CriarVendedor(sqlCommand, true);
- Auxiliar.LoadTipoVendedor(sqlCommand);
- List<Condicao> condicaos = new List<Condicao>()
- {
- new Condicao()
- {
- Campo = "idempresa",
- Valores = idempresa.CriarValor<long>()
- }
- };
- string str = "SELECT * FROM repasse WHERE ";
- string str1 = "SELECT * FROM VinculoRepasse WHERE ";
- List<Condicao> condicaos1 = new List<Condicao>()
- {
- new Condicao()
- {
- Campo = "1",
- Valores = "1".CriarValor<string>()
- }
- };
- if (idempresa > (long)0)
- {
- condicaos1.AddRange(condicaos);
- }
- dataTable = sqlCommand.Select(condicaos1.CreateParameters(0), str, "");
- if (dataTable.Rows.Count != 0)
- {
- for (List<long> i = dataTable.AsEnumerable().Select<DataRow, long>((DataRow x) => x.Field<long>("idrepasse")).Distinct<long>().ToList<long>(); i.Count > 0; i = nums)
- {
- List<long> nums1 = i.Take<long>(2000).ToList<long>();
- List<Condicao> condicaos2 = new List<Condicao>()
- {
- new Condicao()
- {
- Campo = "IdRepasse",
- Valores = nums1.CriarValor<long>()
- }
- };
- DataTable dataTable2 = sqlCommand.Select(condicaos2.CreateParameters(0), str1, "");
- dataTable1.Merge(dataTable2);
- nums = (nums1.Count < 2000 ? new List<long>() : i.Except<long>(nums1).ToList<long>());
- }
- List<Repasse> repasses1 = dataTable.AsEnumerable().Select<DataRow, Repasse>((DataRow x) => {
- long? nullable1;
- long? nullable2;
- Repasse repasse = new Repasse()
- {
- Id = x.Field<long>("idrepasse"),
- Ativo = (x.Field<object>("ativo") == null ? true : x.Field<object>("ativo").ToString() != "0"),
- Base = (x.Field<object>("base") == null ? null : new BaseRepasse?((BaseRepasse)Enum.Parse(typeof(BaseRepasse), x.Field<object>("base").ToString()))),
- Forma = (x.Field<object>("forma") == null ? null : new FormaRepasse?((FormaRepasse)Enum.Parse(typeof(FormaRepasse), x.Field<object>("forma").ToString()))),
- Incidencia = (x.Field<object>("incidencia") == null ? null : new TipoIncidencia?((TipoIncidencia)Enum.Parse(typeof(TipoIncidencia), x.Field<object>("incidencia").ToString()))),
- Tipo = (x.Field<object>("tipo") == null ? null : new TipoRepasse?((TipoRepasse)Enum.Parse(typeof(TipoRepasse), x.Field<object>("tipo").ToString())))
- };
- decimal? nullable3 = x.Field<decimal?>("vlrnovo");
- repasse.ValorNovo = nullable3.GetValueOrDefault();
- nullable3 = x.Field<decimal?>("vlrrenovacao");
- repasse.ValorRenovacao = nullable3.GetValueOrDefault();
- repasse.Vendedor = Auxiliar.Vendedores.FirstOrDefault<Vendedor>((Vendedor z) => z.Id == x.Field<long>("idvendedor"));
- repasse.Ramo = (x.Field<object>("idramo") == null ? null : Auxiliar.Ramos.FirstOrDefault<Ramo>((Ramo z) => {
- long id = z.Id;
- long? nullable = x.Field<long?>("idramo");
- return id == nullable.GetValueOrDefault() & nullable.HasValue;
- }));
- if (x.Field<object>("idciaseg") == null)
- {
- nullable1 = null;
- nullable2 = nullable1;
- }
- else
- {
- Seguradora seguradora = Auxiliar.Seguradoras.FirstOrDefault<Seguradora>((Seguradora z) => {
- long id = z.Id;
- long? nullable = x.Field<long?>("idciaseg");
- return id == nullable.GetValueOrDefault() & nullable.HasValue;
- });
- if (seguradora != null)
- {
- nullable2 = new long?(seguradora.Id);
- }
- else
- {
- nullable1 = null;
- nullable2 = nullable1;
- }
- }
- repasse.Seguradora = nullable2;
- return repasse;
- }).ToList<Repasse>();
- List<Repasse> repasses2 = (
- from x in repasses1
- where x.Ativo
- select x).ToList<Repasse>();
- repasses2.ForEach((Repasse x) => {
- Repasse list = x;
- EnumerableRowCollection<DataRow> dataRows = dataTable1.AsEnumerable().Where<DataRow>((DataRow r) => r.Field<long>("IdRepasse") == x.Id);
- Func<DataRow, VinculoRepasse> u003cu003e9_8 = func1;
- if (u003cu003e9_8 == null)
- {
- Func<DataRow, VinculoRepasse> vinculoRepasse = (DataRow v) => new VinculoRepasse()
- {
- Id = v.Field<long>("Id"),
- IdRepasse = v.Field<long>("IdRepasse"),
- RepasseVinculo = repasses1.Find((Repasse z) => z.Id == v.Field<long>("RepasseVinculo_id")),
- TipoVendedor = Auxiliar.TipoVendedores.Find((TipoVendedor z) => z.Id == v.Field<long>("TipoVendedor_id")),
- TipoVendedorVinculo = Auxiliar.TipoVendedores.Find((TipoVendedor z) => z.Id == v.Field<long>("TipoVendedorVinculo_id"))
- };
- Func<DataRow, VinculoRepasse> func = vinculoRepasse;
- func1 = vinculoRepasse;
- u003cu003e9_8 = func;
- }
- list.Vinculo = dataRows.Select<DataRow, VinculoRepasse>(u003cu003e9_8).ToList<VinculoRepasse>();
- });
- repasses = repasses2;
- }
- else
- {
- repasses = new List<Repasse>();
- }
- }
- }
- return repasses;
- }
-
- public void Delete(long id)
- {
- RepasseDb repasseDb = base.FindEntityById(id);
- if (repasseDb == null)
- {
- return;
- }
- base.Delete(repasseDb);
- }
-
- public void DeleteVinculo(long id)
- {
- VinculoRepasseDb vinculoRepasseDb = this._unitOfWork.Repository<VinculoRepasseDb>().FindEntityById(id);
- if (vinculoRepasseDb == null)
- {
- return;
- }
- this._unitOfWork.Repository<VinculoRepasseDb>().Delete(vinculoRepasseDb);
- }
-
- public Repasse FindById(long id)
- {
- List<VinculoRepasse> vinculoRepasses;
- RepasseDb repasseDb = base.FindEntityById(id);
- List<VinculoRepasse> vinculoRepasses1 = this.FindByRepasse(id);
- Repasse repasse = ApplicationMapper.Mapper.Map<RepasseDb, Repasse>(repasseDb);
- if (vinculoRepasses1 == null || vinculoRepasses1.Count <= 0)
- {
- vinculoRepasses = null;
- }
- else
- {
- vinculoRepasses = vinculoRepasses1;
- }
- repasse.Vinculo = vinculoRepasses;
- return repasse;
- }
-
- public List<VendedorParcela> FindByIdRepasse(long id)
- {
- object connection;
- 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.CriarVendedor(sqlCommand, false);
- sqlCommand.CommandText = string.Format("SELECT idvendedorparcela FROM vendedorparcela WHERE idrepasse = {0}", id);
- using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
- {
- sqlDataAdapter.SelectCommand = sqlCommand;
- sqlDataAdapter.Fill(dataTable);
- }
- }
- }
- return dataTable.AsEnumerable().Select<DataRow, VendedorParcela>((DataRow x) => new VendedorParcela()
- {
- Id = x.Field<long>("idvendedorparcela")
- }).ToList<VendedorParcela>();
- }
-
- public List<Repasse> FindByIdVendedor(long id)
- {
- List<RepasseDb> list = this._unitOfWork.Session.CreateQuery(string.Format("from RepasseDb \r\n where IdVendedor = {0}", id)).List<RepasseDb>().ToList<RepasseDb>();
- List<Repasse> repasses = ApplicationMapper.Mapper.Map<List<RepasseDb>, List<Repasse>>(list);
- repasses.ForEach((Repasse x) => {
- List<VinculoRepasse> vinculoRepasses = this.FindByRepasse(x.Id);
- x.Vinculo = (vinculoRepasses == null || vinculoRepasses.Count <= 0 ? null : vinculoRepasses);
- });
- return repasses;
- }
-
- public List<VinculoRepasse> FindByRepasse(long id)
- {
- List<VinculoRepasseDb> list = (
- from x in this._unitOfWork.Query<VinculoRepasseDb>()
- where x.IdRepasse == id
- select x).ToList<VinculoRepasseDb>();
- return ApplicationMapper.Mapper.Map<List<VinculoRepasseDb>, List<VinculoRepasse>>(list);
- }
-
- public Repasse Merge(Repasse repasse)
- {
- RepasseDb repasseDb = ApplicationMapper.Mapper.Map<Repasse, RepasseDb>(repasse);
- base.Merge(repasseDb);
- return ApplicationMapper.Mapper.Map<RepasseDb, Repasse>(repasseDb);
- }
-
- public VinculoRepasse Merge(VinculoRepasse vinculo)
- {
- VinculoRepasseDb vinculoRepasseDb = ApplicationMapper.Mapper.Map<VinculoRepasse, VinculoRepasseDb>(vinculo);
- this._unitOfWork.Repository<VinculoRepasseDb>().Merge(vinculoRepasseDb);
- return ApplicationMapper.Mapper.Map<VinculoRepasseDb, VinculoRepasse>(vinculoRepasseDb);
- }
-
- public Repasse SaveOrUpdate(Repasse repasse)
- {
- RepasseDb repasseDb = ApplicationMapper.Mapper.Map<Repasse, RepasseDb>(repasse);
- this.SaveOrUpdate(repasseDb);
- return ApplicationMapper.Mapper.Map<RepasseDb, Repasse>(repasseDb);
- }
-
- public VinculoRepasse SaveOrUpdate(VinculoRepasse vinculo)
- {
- VinculoRepasseDb vinculoRepasseDb = ApplicationMapper.Mapper.Map<VinculoRepasse, VinculoRepasseDb>(vinculo);
- this._unitOfWork.Repository<VinculoRepasseDb>().SaveOrUpdate(vinculoRepasseDb);
- return ApplicationMapper.Mapper.Map<VinculoRepasseDb, VinculoRepasse>(vinculoRepasseDb);
- }
- }
-}
\ No newline at end of file |