summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AutoRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AutoRepository.cs')
-rw-r--r--Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AutoRepository.cs607
1 files changed, 607 insertions, 0 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AutoRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AutoRepository.cs
new file mode 100644
index 0000000..7cbb775
--- /dev/null
+++ b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/AutoRepository.cs
@@ -0,0 +1,607 @@
+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.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 AutoRepository : GenericRepository<AutoDb>, IAutoRepository, IGenericRepository<AutoDb>
+ {
+ private readonly GenericUnitOfWork _unitOfWork;
+
+ public AutoRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
+ {
+ this._unitOfWork = unitOfWork;
+ }
+
+ public void Delete(long id)
+ {
+ AutoDb autoDb = base.FindEntityById(id);
+ if (autoDb == null)
+ {
+ return;
+ }
+ base.Delete(autoDb);
+ }
+
+ public void DeleteRange(List<long> ids)
+ {
+ List<AutoDb> list = (
+ from x in base.All()
+ where ids.Contains(x.Item.Id)
+ select x).ToList<AutoDb>();
+ base.DeleteRange(list);
+ }
+
+ public Auto Find(long id)
+ {
+ AutoDb autoDb = base.All().FirstOrDefault<AutoDb>((AutoDb x) => x.Item.Id == id) ?? new AutoDb();
+ return ApplicationMapper.Mapper.Map<AutoDb, Auto>(autoDb);
+ }
+
+ public List<PesquisaAvancada> FindAuto(string pesquisa, FiltroStatusDocumento status, List<VendedorUsuario> vendedorVinculado, TipoPesquisa tipo, bool tipobusca = false)
+ {
+ List<PesquisaAvancada> pesquisaAvancadas;
+ object connection;
+ DataTable dataTable = new DataTable();
+ DataTable dataTable1 = new DataTable();
+ DataTable dataTable2 = new DataTable();
+ DataTable dataTable3 = new DataTable();
+ DateTime date = Funcoes.GetNetworkTime().Date;
+ List<Condicao> condicaos = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "d.excluido",
+ Valores = null,
+ Grupo = 1,
+ Operacao = Operacao.Or
+ },
+ new Condicao()
+ {
+ Campo = "d.excluido",
+ Valores = "0".CriarValor<string>(),
+ Grupo = 1,
+ Operacao = Operacao.Or
+ }
+ };
+ switch (status)
+ {
+ case FiltroStatusDocumento.Vencidos:
+ {
+ condicaos.AddRange(new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = new List<object>()
+ {
+ 3,
+ 7
+ },
+ Operador = Operador.Diferente
+ },
+ new Condicao()
+ {
+ Campo = "d.vigencia2",
+ Valores = date.AddDays(-5).CriarValor<DateTime>(),
+ Operador = Operador.Menor
+ }
+ });
+ goto case FiltroStatusDocumento.Todos;
+ }
+ case FiltroStatusDocumento.Cancelados:
+ {
+ condicaos.Add(new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = 3.CriarValor<int>()
+ });
+ goto case FiltroStatusDocumento.Todos;
+ }
+ case FiltroStatusDocumento.Recusados:
+ {
+ condicaos.Add(new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = 7.CriarValor<int>()
+ });
+ goto case FiltroStatusDocumento.Todos;
+ }
+ case FiltroStatusDocumento.Todos:
+ {
+ 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())
+ {
+ List<Condicao> condicaos1 = new List<Condicao>();
+ if (tipo == TipoPesquisa.Chassi)
+ {
+ condicaos1.Add(new Condicao()
+ {
+ Campo = "a.chassi",
+ Valores = pesquisa.CriarValor<string>(),
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ });
+ }
+ else if (tipo == TipoPesquisa.Item)
+ {
+ condicaos1.Add(new Condicao()
+ {
+ Campo = "i.descricao",
+ Valores = pesquisa.CriarValor<string>(),
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ });
+ }
+ else if (tipo == TipoPesquisa.Placa)
+ {
+ condicaos1.Add(new Condicao()
+ {
+ Campo = "REPLACE(a.placa, '-','')",
+ Valores = pesquisa.Replace("-", "").Replace("?", "%").CriarValor<string>(),
+ Operador = (tipobusca ? Operador.Igual : Operador.Like)
+ });
+ }
+ dataTable = sqlCommand.Select(condicaos1.CreateParameters(0), "SELECT TOP 1000 i.iditem as id FROM item i LEFT OUTER JOIN auto a on i.iditem = a.iditem WHERE ", "");
+ if (dataTable.Rows.Count != 0)
+ {
+ List<Condicao> condicaos2 = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "iditem",
+ Valores = dataTable.AsEnumerable().Select<DataRow, long>((DataRow v) => v.Field<long>("id")).ToList<long>().CriarValor<long>()
+ }
+ };
+ dataTable1 = sqlCommand.Select(condicaos2.CreateParameters(0), "SELECT iddocumento as id, descricao, iditem FROM item WHERE", "");
+ condicaos.Add(new Condicao()
+ {
+ Campo = "d.iddocumento",
+ Valores = dataTable1.AsEnumerable().Select<DataRow, long>((DataRow v) => v.Field<long>("id")).ToList<long>().CriarValor<long>()
+ });
+ dataTable2 = sqlCommand.Select(condicaos.CreateParameters(0), "SELECT DISTINCT cl.nome as cliente, c.idcliente, d.idcontrole, d.iddocumento, situacao, ISNULL(vigencia1, GETDATE()) AS vigencia1, vigencia2, proposta, contrato as apolice, aditamento as endosso, CAST(tipo as INTEGER) as tipo FROM documento d INNER JOIN controle c on c.idcontrole = d.idcontrole INNER JOIN cliente cl on cl.idcliente = c.idcliente WHERE ", "");
+ if (dataTable2.Rows.Count != 0)
+ {
+ List<long> list = (
+ from x in dataTable2.AsEnumerable().ToList<DataRow>()
+ select x.Field<long>("idcontrole")).ToList<long>();
+ List<Condicao> condicaos3 = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "d.idcontrole",
+ Valores = list.CriarValor<long>()
+ }
+ };
+ dataTable3 = sqlCommand.Select(condicaos3.CreateParameters(0), "SELECT DISTINCT vp.idvendedor, d.iddocumento, d.idcontrole, vp.idtipovendedor FROM vendedorparcela vp INNER JOIN documento d on d.iddocumento = vp.iddocumento WHERE ", "");
+ goto Label1;
+ }
+ else
+ {
+ pesquisaAvancadas = new List<PesquisaAvancada>();
+ }
+ }
+ else
+ {
+ pesquisaAvancadas = new List<PesquisaAvancada>();
+ }
+ }
+ }
+ return pesquisaAvancadas;
+ }
+ default:
+ {
+ condicaos.AddRange(new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "d.situacao",
+ Valores = new List<object>()
+ {
+ 1,
+ 2,
+ 4
+ }
+ },
+ new Condicao()
+ {
+ Campo = "d.vigencia2",
+ Valores = null,
+ Grupo = 2,
+ Operacao = Operacao.Or
+ },
+ new Condicao()
+ {
+ Campo = "d.vigencia2",
+ Valores = date.AddDays(-5).CriarValor<DateTime>(),
+ Grupo = 2,
+ Operacao = Operacao.Or,
+ Operador = Operador.Maior
+ }
+ });
+ goto case FiltroStatusDocumento.Todos;
+ }
+ }
+ Label1:
+ List<long> nums = null;
+ if (vendedorVinculado != null && vendedorVinculado.Count > 0)
+ {
+ nums = dataTable3.AsEnumerable().Where<DataRow>((DataRow x) => {
+ List<VendedorUsuario> vendedorUsuarios = vendedorVinculado;
+ Func<VendedorUsuario, long> u003cu003e9_107 = AutoRepository.u003cu003ec.u003cu003e9__10_7;
+ if (u003cu003e9_107 == null)
+ {
+ u003cu003e9_107 = (VendedorUsuario v) => v.Vendedor.Id;
+ AutoRepository.u003cu003ec.u003cu003e9__10_7 = u003cu003e9_107;
+ }
+ return vendedorUsuarios.Select<VendedorUsuario, long>(u003cu003e9_107).Contains<long>(x.Field<long>("idvendedor"));
+ }).Select<DataRow, long>((DataRow x) => x.Field<long>("idcontrole")).ToList<long>();
+ }
+ if (nums != null && nums.Count == 0)
+ {
+ return new List<PesquisaAvancada>();
+ }
+ return dataTable2.AsEnumerable().Where<DataRow>((DataRow x) => {
+ if (nums == null)
+ {
+ return true;
+ }
+ return nums.Contains(x.Field<long>("idcontrole"));
+ }).Select<DataRow, PesquisaAvancada>((DataRow x) => new PesquisaAvancada()
+ {
+ IdCliente = x.Field<long>("idcliente"),
+ IdDocumento = x.Field<long>("iddocumento"),
+ IdItem = dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<long>("iditem"),
+ Nome = x.Field<string>("cliente"),
+ Pesquisa = (x.Field<int>("tipo") == 0 ? string.Format("ITEM: {0} - NÚMERO DA APÓLICE: {1} - NÚMERO DA PROPOSTA: {2} - VIGÊNCIA INICIAL: {3:d} ", new object[] { dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), x.Field<string>("apolice"), x.Field<string>("proposta"), x.Field<DateTime>("vigencia1") }) : string.Format("ITEM: {0} - NÚMERO DA APÓLICE: {1} - NÚMERO DA PROPOSTA: {2} - NÚMERO DO ENDOSSO: {3} VIGÊNCIA INICIAL: {4:d}", new object[] { dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), x.Field<string>("apolice"), x.Field<string>("proposta"), x.Field<string>("endosso"), x.Field<DateTime>("vigencia1") }))
+ }).ToList<PesquisaAvancada>();
+ }
+
+ public Documento FindByChassi(string chassi, long id, DateTime vigencia1, DateTime? vigencia2, long idSeguradora)
+ {
+ DocumentoDb documento;
+ List<TipoSeguro> tipoSeguros = new List<TipoSeguro>()
+ {
+ TipoSeguro.Novo,
+ TipoSeguro.Renovacao,
+ TipoSeguro.Reabilitado
+ };
+ DateTime dateTime3 = Convert.ToDateTime(vigencia2);
+ AutoDb autoDb = (
+ from a in base.All()
+ select new AutoDb()
+ {
+ Id = a.Id,
+ Chassi = a.Chassi,
+ Item = new ItemDb()
+ {
+ Cancelado = a.Item.Cancelado,
+ Substituido = a.Item.Substituido,
+ Documento = new DocumentoDb()
+ {
+ Vigencia1 = a.Item.Documento.Vigencia1,
+ Vigencia2 = a.Item.Documento.Vigencia2,
+ Situacao = a.Item.Documento.Situacao,
+ Excluido = a.Item.Documento.Excluido,
+ Controle = new ControleDb()
+ {
+ Id = a.Item.Documento.Controle.Id,
+ Seguradora = new SeguradoraDb()
+ {
+ Id = a.Item.Documento.Controle.Seguradora.Id,
+ Nome = a.Item.Documento.Controle.Seguradora.Nome,
+ NomeSocial = a.Item.Documento.Controle.Seguradora.NomeSocial
+ },
+ Cliente = new ClienteDb()
+ {
+ Id = a.Item.Documento.Controle.Cliente.Id,
+ Nome = a.Item.Documento.Controle.Cliente.Nome
+ }
+ }
+ }
+ }
+ } into x
+ where x.Id != id && x.Chassi == chassi && tipoSeguros.Contains(x.Item.Documento.Situacao)
+ select x).ToList<AutoDb>().AsEnumerable<AutoDb>().ToList<AutoDb>().Where<AutoDb>((AutoDb x) => {
+ DateTime dateTime = dateTime3;
+ DateTime dateTime4 = x.Item.Documento.Vigencia1;
+ if (dateTime >= dateTime4.AddDays(5))
+ {
+ DateTime dateTime1 = dateTime3;
+ dateTime4 = Convert.ToDateTime(x.Item.Documento.Vigencia2);
+ if (dateTime1 <= dateTime4.AddDays(5))
+ {
+ return true;
+ }
+ }
+ DateTime dateTime2 = vigencia1;
+ dateTime4 = x.Item.Documento.Vigencia1;
+ if (dateTime2 < dateTime4.AddDays(5))
+ {
+ return false;
+ }
+ dateTime4 = vigencia1.AddDays(5);
+ DateTime? nullable1 = x.Item.Documento.Vigencia2;
+ if (!nullable1.HasValue)
+ {
+ return false;
+ }
+ return dateTime4 <= nullable1.GetValueOrDefault();
+ }).ToList<AutoDb>().FirstOrDefault<AutoDb>((AutoDb x) => {
+ long? nullable;
+ if (!x.Item.Cancelado)
+ {
+ long? substituido = x.Item.Substituido;
+ if (!substituido.HasValue && !x.Item.Documento.Excluido)
+ {
+ long num = idSeguradora;
+ ControleDb controle = x.Item.Documento.Controle;
+ if (controle != null)
+ {
+ nullable = new long?(controle.Seguradora.Id);
+ }
+ else
+ {
+ nullable = null;
+ }
+ substituido = nullable;
+ return num == substituido.GetValueOrDefault() & substituido.HasValue;
+ }
+ }
+ return false;
+ });
+ if (autoDb != null)
+ {
+ documento = autoDb.Item.Documento;
+ }
+ else
+ {
+ documento = null;
+ }
+ return ApplicationMapper.Mapper.Map<DocumentoDb, Documento>(documento);
+ }
+
+ public Auto FindById(long id)
+ {
+ AutoDb autoDb = base.FindEntityById(id);
+ return ApplicationMapper.Mapper.Map<AutoDb, Auto>(autoDb);
+ }
+
+ public string FindChassi(long id)
+ {
+ List<Condicao> condicaos = new List<Condicao>()
+ {
+ new Condicao()
+ {
+ Campo = "iditem",
+ Valores = id.CriarValor<long>()
+ }
+ };
+ DataTable dataTable = this._unitOfWork.Select(condicaos.CreateParameters(0), "SELECT chassi FROM auto WHERE ", "");
+ if (dataTable == null)
+ {
+ return null;
+ }
+ DataRow dataRow = dataTable.AsEnumerable().FirstOrDefault<DataRow>();
+ if (dataRow == null)
+ {
+ return null;
+ }
+ return dataRow.Field<string>("chassi");
+ }
+
+ public List<PesquisaAvancada> FindPlaca(string placa, FiltroStatusDocumento status, List<VendedorUsuario> vendedorVinculado)
+ {
+ List<PesquisaAvancada> pesquisaAvancadas;
+ object connection;
+ string str = placa.Replace("-", "");
+ string str1 = str.Insert(3, "-");
+ DataTable dataTable = new DataTable();
+ DataTable dataTable1 = new DataTable();
+ DataTable dataTable2 = new DataTable();
+ DataTable dataTable3 = 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())
+ {
+ sqlCommand.CommandText = string.Concat(new string[] { "SELECT iditem as id FROM auto WHERE placa ='", str, "' OR placa ='", str1, "'" });
+ using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
+ {
+ sqlDataAdapter.SelectCommand = sqlCommand;
+ sqlDataAdapter.Fill(dataTable);
+ }
+ if (dataTable.Rows.Count != 0)
+ {
+ string str2 = string.Concat(" AND iditem IN (", string.Join<long>(",", dataTable.AsEnumerable().Select<DataRow, long>((DataRow v) => v.Field<long>("id"))), ")");
+ sqlCommand.CommandText = string.Concat("SELECT iddocumento as id, descricao, iditem FROM item WHERE 1=1 ", str2);
+ using (SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter())
+ {
+ sqlDataAdapter1.SelectCommand = sqlCommand;
+ sqlDataAdapter1.Fill(dataTable1);
+ }
+ sqlCommand.CommandText = string.Concat("SELECT DISTINCT cl.nome as cliente, c.idcliente, d.idcontrole, d.iddocumento, situacao, vigencia1, vigencia2, proposta, contrato as apolice, aditamento as endosso, CAST(tipo as INTEGER) as tipo FROM documento d INNER JOIN controle c on c.idcontrole = d.idcontrole INNER JOIN cliente cl on cl.idcliente = c.idcliente WHERE (d.excluido IS NULL OR d.excluido != '1') AND d.iddocumento IN (", string.Join<long>(",", dataTable1.AsEnumerable().Select<DataRow, long>((DataRow v) => v.Field<long>("id"))), ")");
+ using (SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter())
+ {
+ sqlDataAdapter2.SelectCommand = sqlCommand;
+ sqlDataAdapter2.Fill(dataTable2);
+ }
+ string str3 = string.Concat(" AND d.idcontrole IN (", string.Join<long>(",", (
+ from x in dataTable2.AsEnumerable().ToList<DataRow>()
+ select x.Field<long>("idcontrole")).ToList<long>()), ")");
+ sqlCommand.CommandText = string.Concat("SELECT DISTINCT vp.idvendedor, d.iddocumento, d.idcontrole, vp.idtipovendedor FROM vendedorparcela vp INNER JOIN documento d on d.iddocumento = vp.iddocumento WHERE 1=1 ", str3);
+ using (SqlDataAdapter sqlDataAdapter3 = new SqlDataAdapter())
+ {
+ sqlDataAdapter3.SelectCommand = sqlCommand;
+ sqlDataAdapter3.Fill(dataTable3);
+ goto Label0;
+ }
+ }
+ else
+ {
+ pesquisaAvancadas = new List<PesquisaAvancada>();
+ }
+ }
+ }
+ return pesquisaAvancadas;
+ Label0:
+ List<long> list = null;
+ if (vendedorVinculado != null && vendedorVinculado.Count > 0)
+ {
+ list = dataTable3.AsEnumerable().Where<DataRow>((DataRow x) => {
+ List<VendedorUsuario> vendedorUsuarios = vendedorVinculado;
+ Func<VendedorUsuario, long> u003cu003e9_915 = AutoRepository.u003cu003ec.u003cu003e9__9_15;
+ if (u003cu003e9_915 == null)
+ {
+ u003cu003e9_915 = (VendedorUsuario v) => v.Vendedor.Id;
+ AutoRepository.u003cu003ec.u003cu003e9__9_15 = u003cu003e9_915;
+ }
+ return vendedorUsuarios.Select<VendedorUsuario, long>(u003cu003e9_915).Contains<long>(x.Field<long>("idvendedor"));
+ }).Select<DataRow, long>((DataRow x) => x.Field<long>("idcontrole")).ToList<long>();
+ }
+ if (list != null && list.Count == 0)
+ {
+ return new List<PesquisaAvancada>();
+ }
+ DateTime date = Funcoes.GetNetworkTime().Date;
+ switch (status)
+ {
+ case FiltroStatusDocumento.Vencidos:
+ {
+ return dataTable2.AsEnumerable().Where<DataRow>((DataRow x) => {
+ if ((list == null || list.Contains(x.Field<long>("idcontrole"))) && (TipoSeguro)Enum.Parse(typeof(TipoSeguro), x.Field<object>("situacao").ToString()) == TipoSeguro.Renovado)
+ {
+ return true;
+ }
+ return x.Field<DateTime>("vigencia2") < date.AddDays(-5);
+ }).Select<DataRow, PesquisaAvancada>((DataRow x) => new PesquisaAvancada()
+ {
+ IdCliente = x.Field<long>("idcliente"),
+ IdDocumento = x.Field<long>("iddocumento"),
+ IdItem = dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<long>("iditem"),
+ Nome = x.Field<string>("cliente"),
+ Pesquisa = (x.Field<int>("tipo") == 0 ? string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta") }) : string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta"), " - NÚMERO DO ENDOSSO: ", x.Field<string>("endosso") }))
+ }).ToList<PesquisaAvancada>();
+ }
+ case FiltroStatusDocumento.Cancelados:
+ {
+ return dataTable2.AsEnumerable().Where<DataRow>((DataRow x) => {
+ if (list != null && !list.Contains(x.Field<long>("idcontrole")))
+ {
+ return false;
+ }
+ return (TipoSeguro)Enum.Parse(typeof(TipoSeguro), x.Field<object>("situacao").ToString()) == TipoSeguro.Cancelado;
+ }).Select<DataRow, PesquisaAvancada>((DataRow x) => new PesquisaAvancada()
+ {
+ IdCliente = x.Field<long>("idcliente"),
+ IdDocumento = x.Field<long>("iddocumento"),
+ IdItem = dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<long>("iditem"),
+ Nome = x.Field<string>("cliente"),
+ Pesquisa = (x.Field<int>("tipo") == 0 ? string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta") }) : string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta"), " - NÚMERO DO ENDOSSO: ", x.Field<string>("endosso") }))
+ }).ToList<PesquisaAvancada>();
+ }
+ case FiltroStatusDocumento.Recusados:
+ {
+ return dataTable2.AsEnumerable().Where<DataRow>((DataRow x) => {
+ if (list != null && !list.Contains(x.Field<long>("idcontrole")))
+ {
+ return false;
+ }
+ return (TipoSeguro)Enum.Parse(typeof(TipoSeguro), x.Field<object>("situacao").ToString()) == TipoSeguro.Recusado;
+ }).Select<DataRow, PesquisaAvancada>((DataRow x) => new PesquisaAvancada()
+ {
+ IdCliente = x.Field<long>("idcliente"),
+ IdDocumento = x.Field<long>("iddocumento"),
+ IdItem = dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<long>("iditem"),
+ Nome = x.Field<string>("cliente"),
+ Pesquisa = (x.Field<int>("tipo") == 0 ? string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta") }) : string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta"), " - NÚMERO DO ENDOSSO: ", x.Field<string>("endosso") }))
+ }).ToList<PesquisaAvancada>();
+ }
+ case FiltroStatusDocumento.Todos:
+ {
+ return dataTable2.AsEnumerable().Where<DataRow>((DataRow x) => {
+ if (list == null)
+ {
+ return true;
+ }
+ return list.Contains(x.Field<long>("idcontrole"));
+ }).Select<DataRow, PesquisaAvancada>((DataRow x) => new PesquisaAvancada()
+ {
+ IdCliente = x.Field<long>("idcliente"),
+ IdDocumento = x.Field<long>("iddocumento"),
+ IdItem = dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<long>("iditem"),
+ Nome = x.Field<string>("cliente"),
+ Pesquisa = (x.Field<int>("tipo") == 0 ? string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta") }) : string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta"), " - NÚMERO DO ENDOSSO: ", x.Field<string>("endosso") }))
+ }).ToList<PesquisaAvancada>();
+ }
+ default:
+ {
+ return dataTable2.AsEnumerable().Where<DataRow>((DataRow x) => {
+ if (list != null && !list.Contains(x.Field<long>("idcontrole")) || (TipoSeguro)Enum.Parse(typeof(TipoSeguro), x.Field<object>("situacao").ToString()) != TipoSeguro.Novo && (TipoSeguro)Enum.Parse(typeof(TipoSeguro), x.Field<object>("situacao").ToString()) != TipoSeguro.Renovacao)
+ {
+ return false;
+ }
+ return x.Field<DateTime>("vigencia2") > date.AddDays(-5);
+ }).Select<DataRow, PesquisaAvancada>((DataRow x) => new PesquisaAvancada()
+ {
+ IdCliente = x.Field<long>("idcliente"),
+ IdDocumento = x.Field<long>("iddocumento"),
+ IdItem = dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<long>("iditem"),
+ Nome = x.Field<string>("cliente"),
+ Pesquisa = (x.Field<int>("tipo") == 0 ? string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta") }) : string.Concat(new string[] { "ITEM: ", dataTable1.AsEnumerable().First<DataRow>((DataRow i) => i.Field<long>("id") == x.Field<long>("iddocumento")).Field<string>("descricao"), " - NÚMERO DA APÓLICE: ", x.Field<string>("apolice"), " - NÚMERO DA PROPOSTA: ", x.Field<string>("proposta"), " - NÚMERO DO ENDOSSO: ", x.Field<string>("endosso") }))
+ }).ToList<PesquisaAvancada>();
+ }
+ }
+ }
+
+ public Auto Merge(Auto auto)
+ {
+ AutoDb autoDb = ApplicationMapper.Mapper.Map<Auto, AutoDb>(auto);
+ base.Merge(autoDb);
+ return ApplicationMapper.Mapper.Map<AutoDb, Auto>(autoDb);
+ }
+
+ public Auto SaveOrUpdate(Auto auto)
+ {
+ AutoDb autoDb = ApplicationMapper.Mapper.Map<Auto, AutoDb>(auto);
+ this.SaveOrUpdate(autoDb);
+ return ApplicationMapper.Mapper.Map<AutoDb, Auto>(autoDb);
+ }
+ }
+} \ No newline at end of file