258 lines
13 KiB
C#
258 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using Ultimus.Utilitarios;
|
|
using System.Data.Entity;
|
|
using ULA.Cathay.CreditoModel.Entidades;
|
|
|
|
namespace ULA.Cathay.CreditoModel.DAL.Credito
|
|
{
|
|
public class ConsultaEpowerDAL
|
|
{
|
|
private UltimusLogs logger = new UltimusLogs("ConsultaEpowerDAL");
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="listaTipoDocumento"></param>
|
|
/// <returns></returns>
|
|
public List<UbicacionEPower> Obtener(List<TipoDocumento> listaTipoDocumento)
|
|
{
|
|
List<UbicacionEPower> listaUbicacionEPower = null;
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var lista = listaTipoDocumento.Select(x => x == null ? (int?)null : x.IdUbicacionEp).ToList();
|
|
listaUbicacionEPower = (from x in db.UbicacionEPower
|
|
.Include("ConsultaEpower.TipoConsultaEpower")
|
|
.Include("ConsultaEpower.ParametroConsultaEpower")
|
|
where lista.Contains(x.IdUbicacionEp) == true
|
|
select x)
|
|
.Include("ConsultaEpower.TipoConsultaEpower")
|
|
.Include("ConsultaEpower.ParametroConsultaEpower")
|
|
.AsNoTracking()
|
|
.ToList();
|
|
for (int i = 0; i < listaUbicacionEPower.Count; i++)
|
|
{
|
|
listaUbicacionEPower[i].ConsultaEpower = listaUbicacionEPower[i].ConsultaEpower.Where(x => x.Estado == true).ToList();
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException ex1)
|
|
{
|
|
logger.Error(ex1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
return listaUbicacionEPower;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="listaBitacoraDocumentosCliente"></param>
|
|
/// <param name="IdSolicitud"></param>
|
|
/// <returns></returns>
|
|
public List<BitacoraDocumentosCliente> ObtenerRutaConsulta(List<BitacoraDocumentosCliente> listaBitacoraDocumentosCliente, int IdSolicitud, int? IdCliente = null)
|
|
{
|
|
List<UbicacionEPower> listaConsultaEpower = new List<UbicacionEPower>();
|
|
List<TipoDocumento> listaTipoDocumento = new List<TipoDocumento>();
|
|
string RutaServerEpower = string.Empty;
|
|
|
|
try
|
|
{
|
|
RutaServerEpower = new Ultimus.Utilitarios.ObtieneParametros().GetValueKeyRegedit("EPower.RutaEIntegrator", false);
|
|
listaTipoDocumento = listaBitacoraDocumentosCliente.Select(x => x.TipoDocumento).ToList();
|
|
listaConsultaEpower = Obtener(listaTipoDocumento);
|
|
foreach (BitacoraDocumentosCliente itemBitacoraDocumentosCliente in listaBitacoraDocumentosCliente)
|
|
{
|
|
itemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower = listaConsultaEpower.Where(x => x.IdUbicacionEp == itemBitacoraDocumentosCliente.TipoDocumento.IdUbicacionEp).FirstOrDefault();
|
|
itemBitacoraDocumentosCliente.RutaEPower = ArmarRutaConsultaEpower(RutaServerEpower, itemBitacoraDocumentosCliente, IdSolicitud, IdCliente);
|
|
itemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
listaConsultaEpower = null;
|
|
listaTipoDocumento = null;
|
|
}
|
|
return listaBitacoraDocumentosCliente;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="RutaServerEpower"></param>
|
|
/// <param name="ItemBitacoraDocumentosCliente"></param>
|
|
/// <param name="IdSolicitud"></param>
|
|
/// <returns></returns>
|
|
private string ArmarRutaConsultaEpower(string RutaServerEpower, BitacoraDocumentosCliente ItemBitacoraDocumentosCliente, int IdSolicitud, int? IdCliente = null, Cliente ClienteActual = null)
|
|
{
|
|
StringBuilder sbRuta = new StringBuilder();
|
|
ConsultaEpower _ConsultaEpowerCurrent = new ConsultaEpower();
|
|
Cliente Solicitante = ClienteActual ?? new Cliente();
|
|
ClienteDAL ConnCliente = new ClienteDAL();
|
|
|
|
try
|
|
{
|
|
if (ItemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower == null)
|
|
{
|
|
sbRuta.Append(string.Format("El documento {0} no posee configuración para el registro en Epower, por favor agregue la ubicación en epower en el mantenimiento de Tipos de Documentos.", ItemBitacoraDocumentosCliente.TipoDocumento.Descripcion));
|
|
return sbRuta.ToString();
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ItemBitacoraDocumentosCliente.RutaEPower))
|
|
sbRuta.AppendFormat(ItemBitacoraDocumentosCliente.RutaEPower);
|
|
else
|
|
{
|
|
if (ClienteActual == null)
|
|
{
|
|
if (IdCliente == null)
|
|
Solicitante = ConnCliente.ObtenerPrincipalSimple(IdSolicitud);
|
|
else
|
|
Solicitante = ConnCliente.Obtener(Convert.ToInt32(IdCliente));
|
|
}
|
|
|
|
if (Solicitante != null)
|
|
{
|
|
switch (ItemBitacoraDocumentosCliente.RegistradoEpower)
|
|
{
|
|
case false:
|
|
_ConsultaEpowerCurrent = ItemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower.ConsultaEpower.FirstOrDefault(x => x.IdTipoConsultaEpower == EnumTipoConsultaEpower.General && x.Estado == true);
|
|
break;
|
|
case true:
|
|
_ConsultaEpowerCurrent = ItemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower.ConsultaEpower.FirstOrDefault(x => x.IdTipoConsultaEpower == EnumTipoConsultaEpower.Especifica && x.Estado == true);
|
|
break;
|
|
}
|
|
sbRuta.AppendFormat(RutaServerEpower);
|
|
sbRuta.AppendFormat("?app={0}", ItemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower.CodigoApp.ToString());
|
|
sbRuta.AppendFormat("&doctype={0}", ItemBitacoraDocumentosCliente.TipoDocumento.UbicacionEPower.CodigoDocType.ToString());
|
|
sbRuta.AppendFormat("&query={0}", _ConsultaEpowerCurrent.CodigoQuery.ToString());
|
|
|
|
foreach (ParametroConsultaEpower ItemParametroConsultaEpower in _ConsultaEpowerCurrent.ParametroConsultaEpower.OrderBy(x => x.Orden))
|
|
{
|
|
string ValorRetorno = string.Empty;
|
|
|
|
switch (ItemParametroConsultaEpower.RefColumn)
|
|
{
|
|
|
|
case "Identificacion": //Con Guiones
|
|
|
|
switch (Solicitante.IdTipoIdentificacion)
|
|
{
|
|
case EnumTipoIdentificacion.Persona_Fisica_Nacional:
|
|
ValorRetorno = Solicitante.NumeroIdentificacion == null ? "" : Solicitante.NumeroIdentificacion.Trim().Substring(1, Solicitante.NumeroIdentificacion.Trim().Length - 1);
|
|
break;
|
|
case EnumTipoIdentificacion.Persona_Juridica_Nacional:
|
|
ValorRetorno = Solicitante.NumeroIdentificacion == null ? "" : string.Format("{0}-{1}-{2}", Solicitante.NumeroIdentificacion.Trim().Substring(0, 1), Solicitante.NumeroIdentificacion.Trim().Substring(1, 3), Solicitante.NumeroIdentificacion.Trim().Substring(4, Solicitante.NumeroIdentificacion.Trim().Length - 4));
|
|
break;
|
|
default:
|
|
ValorRetorno = Solicitante.NumeroIdentificacion == null ? "" : Solicitante.NumeroIdentificacion.Trim();
|
|
break;
|
|
}
|
|
break;
|
|
case "Identificacion2": //Sin Guiones
|
|
|
|
switch (Solicitante.IdTipoIdentificacion)
|
|
{
|
|
case EnumTipoIdentificacion.Persona_Fisica_Nacional:
|
|
ValorRetorno = Solicitante.NumeroIdentificacion == null ? "" : Solicitante.NumeroIdentificacion.Trim().Replace("-", "").Substring(1, Solicitante.NumeroIdentificacion.Trim().Replace("-", "").Length - 1);
|
|
break;
|
|
case EnumTipoIdentificacion.Persona_Juridica_Nacional:
|
|
ValorRetorno = Solicitante.NumeroIdentificacion == null ? "" : Solicitante.NumeroIdentificacion.Trim().Replace("-", "");
|
|
break;
|
|
default:
|
|
ValorRetorno = Solicitante.NumeroIdentificacion == null ? "" : Solicitante.NumeroIdentificacion.Trim().Replace("-", "");
|
|
break;
|
|
}
|
|
break;
|
|
case "TipoDocumento":
|
|
string NombreReferenciaEpower = string.IsNullOrEmpty(ItemBitacoraDocumentosCliente.TipoDocumento.Descripcion) ? "NO DEFINIDO" : ItemBitacoraDocumentosCliente.TipoDocumento.Descripcion.Trim();
|
|
NombreReferenciaEpower = NombreReferenciaEpower.Split(new char[] { '-' })[0];
|
|
ValorRetorno = NombreReferenciaEpower;
|
|
break;
|
|
case "IdTramite":
|
|
ValorRetorno = IdSolicitud.ToString();
|
|
break;
|
|
case "Estado":
|
|
ValorRetorno = "ACTIVO";
|
|
break;
|
|
}
|
|
|
|
sbRuta.AppendFormat("&{0}={1}", ItemParametroConsultaEpower.ParamName, ValorRetorno);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
_ConsultaEpowerCurrent = null;
|
|
Solicitante = null;
|
|
ConnCliente = null;
|
|
}
|
|
return sbRuta.ToString();
|
|
|
|
}
|
|
|
|
|
|
public Solicitud ObtenerRutaConsultaDocumentos(Solicitud solicitud)
|
|
{
|
|
string RutaServerEpower = string.Empty;
|
|
Cliente Principal;
|
|
ClienteDAL ClienteDal;
|
|
try
|
|
{
|
|
ClienteDal = new ClienteDAL();
|
|
RutaServerEpower = new Ultimus.Utilitarios.ObtieneParametros().GetValueKeyRegedit("EPower.RutaEIntegrator", false);
|
|
|
|
Principal = solicitud.Solicitante.Any(c => c.EsPrincipal == true) ? solicitud.Solicitante.FirstOrDefault(c => c.EsPrincipal == true).Cliente
|
|
: ClienteDal.ObtenerPrincipalSimple(solicitud.IdSolicitud);
|
|
|
|
foreach (Solicitante solicitante in solicitud.Solicitante)
|
|
{
|
|
if (solicitante.Cliente.BitacoraDocumentosCliente == null && solicitante.Cliente.BitacoraDocumentosCliente.Count == 0) continue;
|
|
|
|
List<UbicacionEPower> listaConsultaEpower = Obtener(solicitante.Cliente.BitacoraDocumentosCliente.Select(x => x.TipoDocumento).Distinct().ToList());
|
|
|
|
foreach (BitacoraDocumentosCliente documento in solicitante.Cliente.BitacoraDocumentosCliente)
|
|
{
|
|
documento.TipoDocumento.UbicacionEPower = listaConsultaEpower.FirstOrDefault(x => x.IdUbicacionEp == documento.TipoDocumento.IdUbicacionEp);
|
|
documento.RutaEPower = ArmarRutaConsultaEpower(RutaServerEpower, documento, solicitud.IdSolicitud, null, solicitante.Cliente);
|
|
documento.TipoDocumento.UbicacionEPower = null;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
ClienteDal = null;
|
|
Principal = null;
|
|
}
|
|
return solicitud;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|