using System; using System.Collections.Generic; using System.Data.Entity.Validation; using System.Linq; using System.IO; using System.Web; using System.Web.Http; using System.Data.Entity; using ULA.Davivienda.PrendarioModel.Prendario; using ULA.Davivienda.PrestamoAutos.Commons; using ULA.Davivienda.PrestamoAutos.Json; using Ultimus.Interfaces; using System.Configuration; using Ultimus.Interfaces.UltimusForm; using Ultimus.Interfaces.UltimusIntegration; using Ultimus.Interfaces.UltimusRules; using Ultimus.Utilitarios; using ULA.Davivienda.PrestamoAutos.ServiciosCobisConsultaGeneral; using ULA.Davivienda.PrestamoAutos.ServiciosCobisCarteraPrendario; using ULA.Davivienda.PrestamoAutos.WCFServiciosGenerales; using MSXML2; using System.ServiceModel; namespace ULA.Davivienda.PrestamoAutos.ControllersWebApi { public class GlobalAPIController : ApiController { LogFile log = new LogFile(); #region GetControlsSettings [HttpGet] public FormSettingsJSON GetControlsSettings(string keyfiltro, string keyformulario) { return new MenuManager().GetControlsSetting(keyformulario, keyfiltro); } #endregion #region AutenticarUsuario [HttpPost] public AutenticacionUltimus UserAutenticate([FromBody] CredencialesUsuario request) { AutenticacionUltimus ret = new AutenticacionUltimus(); try { string repositoryUrl = new ObtieneParametros().GetValueKeyRegedit("UltimusSignatureUrl", false); ret.Autenticado = new UltimusManager().Autenticate(request.Usuario, request.Contrasena); ret.RutaFirma = new UltimusManager().GetSignature(request.Usuario, repositoryUrl); } catch (Exception Exception) { ret.ResultadoTransaccion.Resultado = false; ret.ResultadoTransaccion.Error = Exception.ToString(); } return ret; } #endregion #region Catalogos #region ObtenerRubroSeguroAuto [HttpGet] public List ObtenerRubroSeguroAuto(string filtro = null) { List ret = null; try { ret = ObtenerRubroSeguro(EnumTipoRubroSeguro.Auto, filtro); } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerRubroSeguroVida [HttpGet] public List ObtenerRubroSeguroVida(string filtro = null) { List ret = null; try { ret = ObtenerRubroSeguro(EnumTipoRubroSeguro.Vida, filtro); } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerRubroSeguroDesempleo [HttpGet] public List ObtenerRubroSeguroDesempleo(string filtro = null) { List ret = null; try { ret = ObtenerRubroSeguro(EnumTipoRubroSeguro.Desempleo, filtro); } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerTipoFuenteIngreso [HttpGet] public List ObtenerTipoFuenteIngreso(string filtro = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = new List(); if (string.IsNullOrWhiteSpace(filtro)) list = db.TipoFuenteIngreso.ToList(); else list = db.TipoFuenteIngreso.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdFuenteIngreso).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerTipoEmpleador [HttpGet] public List ObtenerTipoEmpleador(string filtro = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = new List(); if (string.IsNullOrWhiteSpace(filtro)) list = db.TipoEmpleador.ToList(); else list = db.TipoEmpleador.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdTipoEmpleador).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerProvincia [HttpGet] public List ObtenerProvincia(string filtro = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = new List(); if (string.IsNullOrWhiteSpace(filtro)) list = db.Provincia.ToList(); else list = db.Provincia.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdProvincia).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerCanton [HttpGet] public List ObtenerCanton(string filtro = null, string id = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = db.Canton.ToList(); if (!string.IsNullOrWhiteSpace(id)) { int IdProvincia = Convert.ToInt32(id); list = list.Where(e => e.IdProvincia == IdProvincia).ToList(); } if (string.IsNullOrWhiteSpace(filtro)) list = list.ToList(); else list = list.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdCanton).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerDistrito [HttpGet] public List ObtenerDistrito(string filtro = null, string id = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = db.Distrito.ToList(); if (!string.IsNullOrWhiteSpace(id)) { int IdCanton = Convert.ToInt32(id); list = list.Where(e => e.IdCanton == IdCanton).ToList(); } if (string.IsNullOrWhiteSpace(filtro)) list = list.ToList(); else list = list.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdDistrito).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerPuestoTrabajo [HttpGet] public List ObtenerPuestoTrabajo(string filtro = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = new List(); if (string.IsNullOrWhiteSpace(filtro)) list = db.PuestoActual.ToList(); else list = db.PuestoActual.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdPuestoActual).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerEmpresaPlanilla [HttpGet] public List ObtenerEmpresaPlanilla(string filtro = null) { List ret = new List(); try { //TODO: Integración COBIS JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = "1"; catalogo.descripcion = "EMPRESA 1"; ret.Add(catalogo); catalogo = new JsonCatalogos(); catalogo.codigo = "2"; catalogo.descripcion = "EMPRESA 2"; ret.Add(catalogo); catalogo = new JsonCatalogos(); catalogo.codigo = "3"; catalogo.descripcion = "EMPRESA 3"; ret.Add(catalogo); } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerPais [HttpGet] public List ObtenerPais(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.Nacionalidad.Where(t => t.Estado == true) : db.Nacionalidad.Where(t => t.Estado == true && t.Pais.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdNacionalidad.ToString(), descripcion = t.Pais }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerNacionalidad [HttpGet] public List ObtenerNacionalidad(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.Nacionalidad.Where(t => t.Estado == true) : db.Nacionalidad.Where(t => t.Estado == true && t.Pais.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdNacionalidad.ToString(), descripcion = t.Descripcion }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerGenero [HttpGet] public List ObtenerGenero(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.Genero.Where(t => t.Estado == true) : db.Genero.Where(t => t.Estado == true && t.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdGenero, descripcion = t.Descripcion }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerProfesion [HttpGet] public List ObtenerProfesion(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.Profesion.Where(t => t.Estado == true) : db.Profesion.Where(t => t.Estado == true && t.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdProfesion.ToString(), descripcion = t.Descripcion }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerNivelEducacion [HttpGet] public List ObtenerNivelEducacion(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.NivelEducacion.Where(t => t.Estado == true) : db.NivelEducacion.Where(t => t.Estado == true && t.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdNivelEducacion.ToString(), descripcion = t.Descripcion }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerEstadoCivil [HttpGet] public List ObtenerEstadoCivil(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.EstadoCivil.Where(t => t.Estado == true) : db.EstadoCivil.Where(t => t.Estado == true && t.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdEstadoCivil.Trim(), descripcion = t.Descripcion }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerCondicionVivienda [HttpGet] public List ObtenerCondicionVivienda(string filtro = null) { List registros = null; try { using (PrendarioContext db = new PrendarioContext()) { registros = (string.IsNullOrWhiteSpace(filtro) ? db.CondicionVivienda.Where(t => t.Estado == true) : db.CondicionVivienda.Where(t => t.Estado == true && t.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true)).Select(t => new JsonCatalogos() { codigo = t.IdCondicionVivienda.ToString(), descripcion = t.Descripcion }).ToList(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return registros; } #endregion #region ObtenerAgenciaVehiculo [HttpGet] public List ObtenerAgenciaVehiculo(string filtro = null) { List listaAgenciaVehiculo = null; try { listaAgenciaVehiculo = new List(); List AgenciaVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) AgenciaVehiculo = db.AgenciaVehiculo.Where(e => e.Estado == true).ToList(); else AgenciaVehiculo = db.AgenciaVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in AgenciaVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdAgenciaVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaAgenciaVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaAgenciaVehiculo; } #endregion #region ObtenerAnnoVehiculo [HttpGet] public List ObtenerAnnoVehiculo(string filtro = null) { List listaAnnoVehiculo = null; try { listaAnnoVehiculo = new List(); List AnnoVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) AnnoVehiculo = db.AnnoVehiculo.Where(e => e.Estado == true).ToList(); else AnnoVehiculo = db.AnnoVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) && e.Estado == true).ToList(); foreach (var n in AnnoVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdAnnoVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaAnnoVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaAnnoVehiculo; } #endregion #region ObtenerMarcaVehiculo [HttpGet] public List ObtenerMarcaVehiculo(string filtro = null) { List listaMarcaVehiculo = null; try { listaMarcaVehiculo = new List(); List MarcaVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) MarcaVehiculo = db.MarcaVehiculo.Where(e => e.Estado == true).ToList(); else MarcaVehiculo = db.MarcaVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in MarcaVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdMarcaVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaMarcaVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaMarcaVehiculo; } #endregion #region ObtenerEstiloVehiculo [HttpGet] public List ObtenerEstiloVehiculo(string filtro = null) { List listaEstiloVehiculo = null; try { listaEstiloVehiculo = new List(); List EstiloVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) EstiloVehiculo = db.EstiloVehiculo.Where(e => e.Estado == true).ToList(); else EstiloVehiculo = db.EstiloVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in EstiloVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdEstiloVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaEstiloVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaEstiloVehiculo; } #endregion #region ObtenerUsoVehiculo [HttpGet] public List ObtenerUsoVehiculo(string filtro = null) { List listaUsoVehiculo = null; try { listaUsoVehiculo = new List(); List UsoVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) UsoVehiculo = db.UsoVehiculo.Where(e => e.Estado == true).ToList(); else UsoVehiculo = db.UsoVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in UsoVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdUsoVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaUsoVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaUsoVehiculo; } #endregion #region ObtenerTipoTraccion [HttpGet] public List ObtenerTipoTraccion(string filtro = null) { List listaTipoTraccion = null; try { listaTipoTraccion = new List(); List TipoTraccion = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) TipoTraccion = db.TipoTraccion.Where(e => e.Estado == true).ToList(); else TipoTraccion = db.TipoTraccion.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in TipoTraccion) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdTipoTraccion.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaTipoTraccion.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaTipoTraccion; } #endregion #region ObtenerTipoTransmision [HttpGet] public List ObtenerTipoTransmision(string filtro = null) { List listaTipoTransmision = null; try { listaTipoTransmision = new List(); List TipoTransmision = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) TipoTransmision = db.TipoTransmision.Where(e => e.Estado == true).ToList(); else TipoTransmision = db.TipoTransmision.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in TipoTransmision) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdTipoTransmision.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaTipoTransmision.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaTipoTransmision; } #endregion #region ObtenerTipoCombustible [HttpGet] public List ObtenerTipoCombustible(string filtro = null) { List listaTipoCombustible = null; try { listaTipoCombustible = new List(); List TipoCombustible = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) TipoCombustible = db.TipoCombustible.Where(e => e.Estado == true).ToList(); else TipoCombustible = db.TipoCombustible.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in TipoCombustible) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdTipoCombustible.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaTipoCombustible.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaTipoCombustible; } #endregion #region ObtenerDecision [HttpGet] public List ObtenerDecision(string filtro = null, string id = null, string id2 = null, string id3 = null, string id4 = null) { List ret = new List(); try { using (PrendarioContext db = new PrendarioContext()) { List list = new List(); if (!string.IsNullOrEmpty(id4)) { int IdCotizacion = Convert.ToInt32(id4); Cotizacion cot = db.Cotizacion.Where(q => q.IdCotizacion == IdCotizacion).FirstOrDefault(); if (cot != null) { decimal monto = 0; if (cot.MontoPrestamo != null) monto = cot.MontoPrestamo.Value; List tmpList = (from de in db.DecisionPorEtapa.Include("Decision") where de.Proceso == id && de.Etapa == id2 select de).ToList(); foreach (var tmpEle in tmpList) { bool cumpleMontoMin = true; bool cumpleMontoMax = true; bool cumpleGrupoIn = true; bool cumpleGrupoNotIn = true; if (tmpEle.MontoMin != null) { cumpleMontoMin = monto >= tmpEle.MontoMin.Value; } if (tmpEle.MontoMax != null) { cumpleMontoMax = monto <= tmpEle.MontoMax.Value; } if (tmpEle.GrupoIn != null && !string.IsNullOrEmpty(tmpEle.GrupoIn)) { cumpleGrupoIn = new UltimusManager().IsMemberOfGroup(id3, tmpEle.GrupoIn); } if (tmpEle.GrupoNotIn != null && !string.IsNullOrEmpty(tmpEle.GrupoNotIn)) { cumpleGrupoNotIn = !new UltimusManager().IsMemberOfGroup(id3, tmpEle.GrupoNotIn); } if (cumpleMontoMin && cumpleMontoMax && cumpleGrupoIn && cumpleGrupoNotIn) { list.Add(tmpEle.Decision); } } if (string.IsNullOrWhiteSpace(filtro)) list = list.ToList(); else list = list.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = Convert.ToString(ele.IdDecision).Trim(); catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim(); ret.Add(catalogo); } } } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return ret; } #endregion #region ObtenerTipoCuenta [HttpGet] public List ObtenerTipoCuenta(string filtro = null) { List listaTipoCuenta = null; try { listaTipoCuenta = new List(); List tipocuenta = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) tipocuenta = db.TipoCuenta.Where(e => e.Estado == true).ToList(); else tipocuenta = db.TipoCuenta.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in tipocuenta) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdTipoCuenta.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaTipoCuenta.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaTipoCuenta; } #endregion #region ObtenerCuenta [HttpGet] public List ObtenerCuenta(int sol_co_solicitud) { List listaCuentasInternas = null; try { listaCuentasInternas = new List(); List cuenta = new List(); using (PrendarioContext db = new PrendarioContext()) { if (sol_co_solicitud != null) cuenta = db.CuentasInternas.Where(e => e.IdSolicitud == sol_co_solicitud).ToList(); foreach (var n in cuenta) { JsonCuentas catalogo = new JsonCuentas(); catalogo.Codigo = n.IdCuenta.ToString().Trim(); catalogo.Cuenta = n.Ncuenta.ToString().Trim(); catalogo.Moneda = db.Moneda.Where(m => m.IdMoneda == n.IdMoneda).FirstOrDefault().Descripcion; listaCuentasInternas.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaCuentasInternas; } #endregion #region ObtenerTipoEnvioCuenta [HttpGet] public List ObtenerTipoEnvioCuenta(string filtro = null) { List listaTipoEnvioCuenta = null; try { listaTipoEnvioCuenta = new List(); List tipoenviocuenta = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) tipoenviocuenta = db.TipoEnvioCuenta.Where(e => e.Estado == true).ToList(); else tipoenviocuenta = db.TipoEnvioCuenta.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in tipoenviocuenta) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdTipoEnvioCuenta.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaTipoEnvioCuenta.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaTipoEnvioCuenta; } #endregion #region ObtenerFormaPago [HttpGet] public List ObtenerFormaPago(string filtro = null) { List listaFormaPago = null; try { listaFormaPago = new List(); List formapago = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) formapago = db.FormaPago.Where(e => e.Estado == true).ToList(); else formapago = db.FormaPago.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in formapago) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdFormaPago.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaFormaPago.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaFormaPago; } #endregion #region ObtenerAgenteSeguros [HttpGet] public List ObtenerAgenteSeguros(string filtro = null) { List listaAgenteSeguros = null; try { listaAgenteSeguros = new List(); List itemAgenteSeguro = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) itemAgenteSeguro = db.AgenteSeguro.Where(e => e.Estado == true).ToList(); else itemAgenteSeguro = db.AgenteSeguro.Where(e => e.NombreCompleto.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in itemAgenteSeguro) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdAgenteSeguro.ToString().Trim(); catalogo.descripcion = n.NombreCompleto.ToString().Trim() + " - Licencia:" + n.NumLicencia.ToString().Trim(); listaAgenteSeguros.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaAgenteSeguros; } #endregion #region ObtenerCategoriaVehiculo [HttpGet] public List ObtenerCategoriaVehiculo(string filtro = null) { List listaCategoriaVehiculo = null; try { listaCategoriaVehiculo = new List(); List itemCategoriaVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) itemCategoriaVehiculo = db.CategoriaVehiculo.Where(e => e.Estado == true).ToList(); else itemCategoriaVehiculo = db.CategoriaVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in itemCategoriaVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdCategoriaVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaCategoriaVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaCategoriaVehiculo; } #endregion #region ObtenerCarroceriaVehiculo [HttpGet] public List ObtenerCarroceriaVehiculo(string filtro = null) { List listaCarroceriaVehiculo = null; try { listaCarroceriaVehiculo = new List(); List itemCarroceriaVehiculo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) itemCarroceriaVehiculo = db.CarroceriaVehiculo.Where(e => e.Estado == true).ToList(); else itemCarroceriaVehiculo = db.CarroceriaVehiculo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true).ToList(); foreach (var n in itemCarroceriaVehiculo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdCarroceriaVehiculo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaCarroceriaVehiculo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaCarroceriaVehiculo; } #endregion #region ObtenerMotivo [HttpGet] public List ObtenerMotivo(string filtro = null, int? id = null) { List listaMotivo = null; try { listaMotivo = new List(); List itemMotivo = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) itemMotivo = db.Motivo.Where(e => e.Estado == true && e.IdTipoMotivo == id).ToList(); else itemMotivo = db.Motivo.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true && e.IdTipoMotivo == id).ToList(); foreach (var n in itemMotivo) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdMotivo.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaMotivo.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaMotivo; } #endregion #region ObtenerSucursal [HttpGet] public List ObtenerSucursal(string filtro = null, int? id = null) { List listaSucursal = null; try { listaSucursal = new List(); List itemSucursal = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) itemSucursal = db.Sucursal.Where(e => e.Estado == true).ToList(); else itemSucursal = db.Sucursal.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.Estado == true && e.IdSucursal == id).ToList(); foreach (var n in itemSucursal) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = n.IdSucursal.ToString().Trim(); catalogo.descripcion = n.Descripcion.ToString().Trim(); listaSucursal.Add(catalogo); } } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return listaSucursal; } #endregion #endregion #region Enviar [HttpPost] public JsonResponseBase Enviar([FromBody] JsonEnviarCotizacion request) { string proximaEtapa = string.Empty; JsonResponseBase respuesta = new JsonResponseBase(); HistorialDecision _model = new HistorialDecision(); try { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Inicia Envio"); using (PrendarioContext db = new PrendarioContext()) { #region VALIDACIONES if (string.IsNullOrEmpty(request.UserId)) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = "Verificar el UserId"; return respuesta; } if (string.IsNullOrEmpty(request.TaskId)) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = "Verificar el TaskId"; return respuesta; } if (string.IsNullOrEmpty(request.Process)) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = "Verificar el proceso"; return respuesta; } if (string.IsNullOrEmpty(request.Step)) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = "Verificar la tarea"; return respuesta; } Cotizacion cot = db.Cotizacion.Where(q => q.IdCotizacion == request.IdCotizacion).FirstOrDefault(); if (cot == null) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = string.Format("La cotización {0} no existe", request.IdCotizacion); return respuesta; } EjecutivoCotizacion eje = db.EjecutivoCotizacion.Where(q => q.IdCotizacion == request.IdCotizacion).FirstOrDefault(); if (eje == null) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = string.Format("El ejectuvo relacionado con la cotización {0} no existe", request.IdCotizacion); return respuesta; } Solicitud sol = db.Solicitud.Where(q => q.IdCotizacion == request.IdCotizacion).FirstOrDefault(); if (sol == null) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = string.Format("La solicitud relacionada con la cotización {0} no existe", request.IdCotizacion); return respuesta; } Solicitante solte = db.Solicitante.Include(e => e.Cliente).Where(q => q.IdSolicitud == sol.IdSolicitud && q.IdTipoSolicitante == (int)EnumTipoSolicitante.Deudor).FirstOrDefault(); if (solte == null) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = string.Format("El deudor relacionado con la solicitud {0} no existe", sol.IdSolicitud); return respuesta; } InformacionLaboralCliente laboral = db.InformacionLaboralCliente.Where(q => q.IdCliente == solte.IdCliente && q.Valido == true).FirstOrDefault(); if (laboral == null) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = "Actualice la información laboral del deudor"; return respuesta; } #endregion log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Termina Validaciones"); switch (request.Step) { case EnumEtapas.EtapaCotizacion: List listHistorial = db.HistorialDecision .Where(e => e.IdDecision == EnumDecision.IrACotizacion && e.IdSolicitud == request.IdSolicitud).ToList(); if (listHistorial.Count > 0) { int _IdHistorialDecision = listHistorial.Max(e => e.IdHistorialDecision); HistorialDecision _UltimoHistoricoDecision = db.HistorialDecision .Include(e => e.Etapas) .Where(e => e.IdHistorialDecision == _IdHistorialDecision).FirstOrDefault(); if (_UltimoHistoricoDecision != null) { switch (_UltimoHistoricoDecision.Etapas.DescripcionEtapa) { case EnumEtapas.EtapaAprobacion1: request.IdDecision = EnumDecision.IrAAprobacion1.ToString(); break; case EnumEtapas.EtapaAprobacion2: request.IdDecision = EnumDecision.IrAAprobacion2.ToString(); break; } } } break; case EnumEtapas.EtapaAprobacion2: switch (request.IdDecision) { case "14": proximaEtapa = EnumEtapas.EtapaCotizacion; break; } break; default: break; } if (string.IsNullOrEmpty(proximaEtapa)) { List rules = new List(); rules.Add(new RuleVariable() { Name = "DECISION", Value = request.IdDecision }); proximaEtapa = new RulesManager().ObtenerProximaEtapa(request.Process, request.Step, request.Incident, rules); } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Termina Busqueda de Reglas de Etapa"); if (string.IsNullOrEmpty(proximaEtapa)) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString(); respuesta.DescripcionRespuesta = "Verificar las reglas"; return respuesta; } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Inicia armado de estructuras para el Integration Layer"); UltimusManager um = new UltimusManager(); string memo = ""; string summary = sol.IdSolicitud.ToString() + " - " + (string.IsNullOrEmpty(solte.Cliente.PrimerNombre) ? "" : " " + solte.Cliente.PrimerNombre.Trim()) + (string.IsNullOrEmpty(solte.Cliente.SegundoNombre) ? "" : " " + solte.Cliente.SegundoNombre.Trim()) + (string.IsNullOrEmpty(solte.Cliente.PrimerApellido) ? "" : " " + solte.Cliente.PrimerApellido.Trim()) + (string.IsNullOrEmpty(solte.Cliente.SegundoApellido) ? "" : " " + solte.Cliente.SegundoApellido.Trim()); List variables = new List(); variables.Add(new NodeVariables() { NodeName = "TaskData.Global.Etapa", NodeValue = proximaEtapa }); if (request.Incident == 0) { List ejecutivoCargoVenta = new List(); ejecutivoCargoVenta.Add(string.Format("USER:org=Business Organization, user={0}", request.UserId)); ejecutivoCargoVenta.Add(string.Format("USER:org=Business Organization, user={0}/{1}", new ObtieneParametros().GetValueKeyRegedit("UltimusDomains", false), eje.LoginEjecutivo)); variables.Add(new NodeVariables() { NodeName = "TaskData.Global.RecipienteIniciadorEjecutivoCargoVenta", NodeValues = ejecutivoCargoVenta }); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", string.Format("Process:{0} Step:{1} Incident:{2} IdSolicitud:{3} TaskData.Global.RecipienteIniciadorEjecutivoCargoVenta:{4}", request.Process, request.Step, request.Incident, request.IdSolicitud, string.Join(";", ejecutivoCargoVenta))); } //////// WSHttpBinding binding = new WSHttpBinding(); binding.Security.Mode = SecurityMode.None; binding.MaxReceivedMessageSize = int.MaxValue; binding.MaxBufferPoolSize = int.MaxValue; binding.CloseTimeout = new TimeSpan(0, 5, 0); binding.OpenTimeout = new TimeSpan(0, 5, 0); binding.ReceiveTimeout = new TimeSpan(0, 5, 0); binding.SendTimeout = new TimeSpan(0, 5, 0); HttpTransportSecurity security = new HttpTransportSecurity(); security.ClientCredentialType = HttpClientCredentialType.None; binding.Security.Transport = security; string UrlIntegration = new ObtieneParametros().GetValueKeyRegedit("UltimusIntegrationLayerUrl", false); EndpointAddress EndPoint = new EndpointAddress(UrlIntegration); int incidente = 0; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Inicia envio al Integration Layer"); using (Ultimus.Interfaces.UltimusIntegration.UltimusIntegrationClient IntClient = new UltimusIntegrationClient(binding, EndPoint)) { Ultimus.Interfaces.UltimusIntegration.UltimusIncident ui; string sError = ""; if (IntClient.GetTask(request.UserId, request.TaskId, out ui, out sError)) { if (!IntClient.CompleteTaskWithVariables(request.UserId, request.TaskId, memo, summary, variables, out incidente, out sError)) { throw new Exception("CompleteTaskWithVariables error: " + sError); } } else { throw new Exception("GetTask error: " + sError); } } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Terminó envio al Integration Layer"); //// //int incidente = um.CompleteTask(request.UserId, request.TaskId, memo, summary, variables); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Inicia guardado de Incidente"); if (request.Incident == 0) { cot.EstadoCotiza = (int)EnumEstadoCotiza.Enviada; db.Cotizacion.Attach(cot); db.Entry(cot).State = System.Data.Entity.EntityState.Modified; sol.Incidente = incidente; db.Solicitud.Attach(sol); db.Entry(sol).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Inicia registro del historial"); #region HistorialDecision try { int IdHistorialDecision = 1; if (db.HistorialDecision.Count() > 0) IdHistorialDecision = db.HistorialDecision.Max(q => q.IdHistorialDecision) + 1; _model.IdHistorialDecision = IdHistorialDecision; _model.IdSolicitud = request.IdSolicitud; _model.IdEtapa = db.Etapas.Where(x => x.DescripcionEtapa.Trim() == request.Step).FirstOrDefault().IdEtapa; if (_model.IdEtapa == 1) _model.IdDecision = 1; else _model.IdDecision = int.Parse(request.IdDecision); _model.IdMotivo = request.IdMotivo; _model.UsuarioFirma = request.UserId; db.HistorialDecision.Add(_model); db.SaveChanges(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Termina Envio"); } catch (Exception ex2) { Exception Exp = ex2; while (Exp != null) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", Exp); Exp = Exp.InnerException; } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex2); } #endregion respuesta.Incidente = incidente; respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } } catch (DbEntityValidationException ex) { try { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = exceptionMessage; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", exceptionMessage); } catch (Exception) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; Exception Exp = ex; while (Exp != null) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", Exp); Exp = Exp.InnerException; } } return respuesta; } #endregion #region Comentarios [HttpPost] public List ObtenerBitacoraComentarios([FromBody] BitacoraComentarios bitacoraComentarios) { return new MenuManager().ObtenerComentariosProceso(bitacoraComentarios); } [HttpPost] public string GuardarComentarioProceso([FromBody] BitacoraComentarios bitacoraComentarios) { return new MenuManager().GuardarComentarioProceso(bitacoraComentarios); } #endregion #region ConsultarTasaCambio [HttpPost] public JsonConsultarTipoCambio ConsultarTasaCambio(JsonConsultarTipoCambio req) { JsonConsultarTipoCambio respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisConsultaGeneral.ConsultarTasaCambioResponse resp = null; try { respuesta = new JsonConsultarTipoCambio(); interfaces = new InterfacesAPIController(); resp = interfaces.ConsultarTasaCambio(new ServiciosCobisConsultaGeneral.ConsultarTasaCambioRequest() { Proceso = ServiciosCobisConsultaGeneral.EnumeradorProcesoUltimus.PrestamoPrendario, UserName = req.Usuario, Password = "" }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.TipoCambioVenta)) { throw new Exception("No se pudo obtener la tasa de tipo de cambio. Por favor comuniquese con el Administrador del Sistema."); } respuesta.TipoCambioCompra = decimal.Parse(resp.TipoCambioCompra); respuesta.TipoCambioVenta = decimal.Parse(resp.TipoCambioVenta); respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region StringToDateTime public static DateTime? StringToDateTime(string value, int format) { DateTime? dtReturn = null; try { value = value.Replace('/', '-'); string[] arrValue = value.Split(new char[] { '-' }); switch (format) { case 1: //dd-mm-yyyy dtReturn = new DateTime(int.Parse(arrValue[2]), int.Parse(arrValue[1]), int.Parse(arrValue[0])); break; case 2://mm-dd-yyyy dtReturn = new DateTime(int.Parse(arrValue[2]), int.Parse(arrValue[0]), int.Parse(arrValue[1])); break; case 3://yyyy-mm-dd dtReturn = new DateTime(int.Parse(arrValue[0]), int.Parse(arrValue[1]), int.Parse(arrValue[2])); break; default: break; } } catch (Exception) { dtReturn = null; } return dtReturn; } #endregion #region StringToInteger public static int? StringToInteger(string value) { int? nReturn = null; try { nReturn = int.Parse(value); } catch (Exception) { nReturn = null; } return nReturn; } #endregion #region StringToDecimal public static decimal? StringToDecimal(string value) { decimal? nReturn = null; try { nReturn = decimal.Parse(value); } catch (Exception) { nReturn = null; } return nReturn; } #endregion #region IsNumeric public static bool IsNumeric(string value) { double nReturn = 0; bool bResult = false; try { nReturn = double.Parse(value); bResult = true; } catch (Exception) { } return bResult; } #endregion #region ActualizarDatosOperacion private void ActualizarDatosOperacion(DataFaseII Model) { try { using (PrendarioContext db = new PrendarioContext()) { DataFaseII data = db.DataFaseII.Where(x => x.IdSolicitud == Model.IdSolicitud).FirstOrDefault(); db.Entry(data).State = EntityState.Detached; db.DataFaseII.Attach(Model); db.Entry(Model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); UltimusLogs.logger.Error(exceptionMessage); throw ex; } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); throw ex; } } #endregion #region Conexion [HttpPost] public JsonConexion ObtenerConexion([FromBody] JsonConexion Conexion) { JsonConexion respuesta = new JsonConexion(); try { using (PrendarioContext db = new PrendarioContext()) { respuesta.RolUsuario = db.RolUsuario.Where(x => x.Usuario == Conexion.RolUsuario.Usuario).FirstOrDefault(); } } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); } return respuesta; } [HttpPost] public JsonResponseBase GuardarConexion([FromBody] JsonConexion Conexion) { JsonResponseBase respuesta = new JsonResponseBase(); try { using (PrendarioContext db = new PrendarioContext()) { RolUsuario rol = db.RolUsuario.Where(x => x.Usuario == Conexion.RolUsuario.Usuario).FirstOrDefault(); if (rol == null) { db.RolUsuario.Add(Conexion.RolUsuario); } else { db.Entry(rol).State = EntityState.Detached; db.RolUsuario.Attach(Conexion.RolUsuario); db.Entry(Conexion.RolUsuario).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = exceptionMessage; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", exceptionMessage); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region GuardarDatosDecision public void GuardarDatosDecision(JsonEnviarCotizacion Model) { HistorialDecision _model = new HistorialDecision(); try { using (PrendarioContext db = new PrendarioContext()) { int IdHistorialDecision = 1; if (db.HistorialDecision.Count() > 0) IdHistorialDecision = db.HistorialDecision.Max(q => q.IdHistorialDecision) + 1; _model.IdHistorialDecision = IdHistorialDecision; _model.IdSolicitud = Model.IdSolicitud; _model.IdEtapa = db.Etapas.Where(x => x.DescripcionEtapa.Trim() == Model.Step).FirstOrDefault().IdEtapa; _model.IdDecision = int.Parse(Model.IdDecision); _model.IdMotivo = Model.IdMotivo; _model.UsuarioFirma = Model.UserId; db.HistorialDecision.Add(_model); db.SaveChanges(); } } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); UltimusLogs.logger.Error(exceptionMessage); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", exceptionMessage); throw ex; } catch (Exception ex) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); throw ex; } } #endregion #region ActualizarOperacion [HttpPost] public JsonActualizarOperacionResponse ActualizarOperacion(JsonActualizarOperacionRequest req) { JsonActualizarOperacionResponse respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisCarteraPrendario.ActualizarOperacionCompletaResponse resp = null; string NoOperacion = ""; DateTime? FechaInicioOperacion = null; int? PlazoMeses = 0; decimal? MontoPrestamo = 0; try { respuesta = new JsonActualizarOperacionResponse(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { Solicitud _modelSolicitud = (db.Solicitud .Include(e => e.Cotizacion) .Include(e => e.DataFaseII) .Where(e => e.IdSolicitud == req.IdSolicitud)).FirstOrDefault(); _modelSolicitud.AplicaIntegracionConCartera = _modelSolicitud.AplicaIntegracionConCartera.HasValue ? _modelSolicitud.AplicaIntegracionConCartera : false; if (_modelSolicitud.AplicaIntegracionConCartera.Value) { DataFaseII _modelDataFaseII = _modelSolicitud.DataFaseII.First(); Cotizacion _modelCotizacion = _modelSolicitud.Cotizacion; NoOperacion = _modelDataFaseII.NoOperacion.ToString(); JsonFechaProcesoCobis respFechaProceso = ObtenerFechaProcesoCobis(new JsonRegistrarTasaEscalonadaRequest() { UserId = req.UserId }); if (respFechaProceso.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respFechaProceso.DescripcionRespuesta); } try { System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture; FechaInicioOperacion = DateTime.ParseExact(respFechaProceso.FechaProceso, "dd/MM/yyyy", provider); } catch (Exception) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Fecha Proceso: " + respFechaProceso.FechaProceso); throw new Exception("No fue posible recuperar la fecha de proceso de cobis para ejecutar la regeneración de fechas"); } PlazoMeses = _modelCotizacion.PeriodoMesesCredito; MontoPrestamo = _modelCotizacion.MontoPrestamo; string xmlPath = string.Format("{0}\\ActualizarOperacion.xml", ConfigurationManager.AppSettings["XmlPath"]); string xmlString = File.ReadAllText(xmlPath); xmlString = xmlString.Replace("", string.Format("{0}", NoOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", FechaInicioOperacion.Value.ToString("yyyy-MM-dd") + "T06:00:00.0000Z")); xmlString = xmlString.Replace("", string.Format("{0}", PlazoMeses.Value.ToString())); xmlString = xmlString.Replace("", string.Format("{0}", MontoPrestamo.Value.ToString())); resp = interfaces.ActualizarOperacionCompleta(new ServiciosCobisCarteraPrendario.ActualizarOperacionCompletaRequest() { Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario.ToString(), EstadoEtapa = req.TaskStatus, Solicitud = req.IdSolicitud.ToString(), strXML = xmlString, Usuario = req.UserId }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta de cobis. Por favor comuniquese con el Administrador del Sistema."); } MSXML2.DOMDocument xmlRespuesta = new DOMDocument(); xmlRespuesta.loadXML(resp.resultado); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 1"); respuesta.NoOperacion = xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("num_operacion").text; respuesta.FechaInicioPrestamo = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fecha_inicio").text, 1); respuesta.FechaRegeneracion = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fecha_inicio").text, 1); respuesta.FechaFinPrestamo = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fecha_vencim").text, 1); respuesta.FechaPrimerPagoCapital = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fe_1_pago_cap").text, 1); respuesta.FechaPrimerPagoInteres = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fe_1_pago_int").text, 1); respuesta.NumCuotas = StringToInteger(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("num_cuotas").text); respuesta.PlazoEnDias = StringToInteger(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("plazo_dias").text); respuesta.NumeroOperacionesVigentes = StringToInteger(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("nu_ope_vigentes").text); respuesta.MontoDesembolso = StringToDecimal(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("monto_desembolso").text); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 2"); _modelDataFaseII.FechaInicio = respuesta.FechaInicioPrestamo; _modelDataFaseII.FechaFin = respuesta.FechaFinPrestamo; _modelDataFaseII.FechaPrimerPagoCapital = respuesta.FechaPrimerPagoCapital; _modelDataFaseII.FechaPrimerPagoInteres = respuesta.FechaPrimerPagoInteres; _modelDataFaseII.NumCuotas = respuesta.NumCuotas; _modelDataFaseII.PlazoEnDias = respuesta.PlazoEnDias; _modelDataFaseII.NumOperacionesVigentes = respuesta.NumeroOperacionesVigentes; _modelDataFaseII.MontoDesembolso = respuesta.MontoDesembolso; _modelDataFaseII.FechaRegeneracion = respuesta.FechaRegeneracion; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 3"); ActualizarDatosOperacion(_modelDataFaseII); } } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Exitoso la actualizacion de operacion"); //Invoca el registro de la tasa escalonada para la operacion en Cartera JsonResponseBase respTasaEscalonada = RegistrarTasascalonada(new JsonRegistrarTasaEscalonadaRequest() { FechaPrimerPago = respuesta.FechaPrimerPagoCapital, NoOperacion = respuesta.NoOperacion, IdSolicitud = (int)req.IdSolicitud, ProcessName = req.ProcessName, UserId = req.UserId }); //Por favor no cambiar codigo if (respTasaEscalonada.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respTasaEscalonada.DescripcionRespuesta); } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Exitoso la creación de los escalonamientos de operacion"); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region LiquidarOperacion [HttpPost] public JsonLiquidarOperacionResponse LiquidarOperacion(JsonLiquidarOperacionRequest req) { JsonLiquidarOperacionResponse respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisCarteraPrendario.GenerarLiquidacionCompletaResponse resp = null; string NoGarantia = ""; string NoPoliza = ""; string NoBien = ""; string NoOperacion = ""; DateTime? FechaLiquidacionOperacion = null; try { respuesta = new JsonLiquidarOperacionResponse(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { Solicitud _modelSolicitud = (db.Solicitud.Include(e => e.DataFaseII) .Where(e => e.IdSolicitud == req.IdSolicitud)).FirstOrDefault(); _modelSolicitud.AplicaIntegracionConCartera = _modelSolicitud.AplicaIntegracionConCartera.HasValue ? _modelSolicitud.AplicaIntegracionConCartera : false; if (_modelSolicitud.AplicaIntegracionConCartera.Value) { DataFaseII _modelDataFaseII = _modelSolicitud.DataFaseII.First(); NoOperacion = _modelDataFaseII.NoOperacion.ToString(); FechaLiquidacionOperacion = _modelDataFaseII.FechaRegeneracion; NoGarantia = _modelDataFaseII.NumeroGarantia; NoPoliza = _modelDataFaseII.PolizaAuto; NoBien = _modelDataFaseII.ConsecutivoBien; string xmlPath = string.Format("{0}\\Liquidacion.xml", ConfigurationManager.AppSettings["XmlPath"]); string xmlString = File.ReadAllText(xmlPath); xmlString = xmlString.Replace("", string.Format("{0}", NoOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", FechaLiquidacionOperacion.Value.ToString("yyyy-MM-dd") + "T06:00:00.0000Z")); xmlString = xmlString.Replace("", string.Format("{0}", NoGarantia.ToUpper())); xmlString = xmlString.Replace("", string.Format("{0}", NoPoliza.ToUpper())); xmlString = xmlString.Replace("", string.Format("{0}", NoBien.ToUpper())); resp = interfaces.GenerarLiquidacionCompleta(new ServiciosCobisCarteraPrendario.GenerarLiquidacionCompletaRequest() { Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario.ToString(), NumOperacion = NoOperacion, Solicitud = req.IdSolicitud.ToString(), strXML = xmlString, Usuario = req.UserId }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta de la liquidacion en cobis. Por favor comuniquese con el Administrador del Sistema."); } MSXML2.DOMDocument xmlRespuesta = new DOMDocument(); xmlRespuesta.loadXML(resp.resultado); if (xmlRespuesta.documentElement.selectSingleNode("ERROR") != null) { throw new Exception(xmlRespuesta.documentElement.selectSingleNode("ERROR").text); } if (xmlRespuesta.documentElement.selectSingleNode("DatosGenerarLiquidacionCompleta/DatosRegistrarLiquidacion/DatosLiquidacion") != null) { string estadoLiquidacionEnCobis = xmlRespuesta.documentElement.selectSingleNode("DatosGenerarLiquidacionCompleta/DatosRegistrarLiquidacion/DatosLiquidacion").selectSingleNode("ESTADOPROCESO").text; if (estadoLiquidacionEnCobis.ToUpper() == "N") { throw new Exception("Estado de la liquidación en cobis es diferente de satisfactorio."); } } } } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; respuesta.Alertas.Add(ex.Message); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region CrearOperacion [HttpPost] public JsonCrearOperacionResponse CrearOperacion(JsonCrearOperacionRequest req) { JsonCrearOperacionResponse respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisCarteraPrendario.GenerarOperacionCompletaResponse resp = null; string IdActividadEconomica = ""; string IdBanderaBaseCalendario = ""; string IdCiudad = ""; string EnteDeudor = ""; string EnteCodeudor1 = ""; string EnteCodeudor2 = ""; string IdTipoCartera = ""; string CodigoOficial = ""; string IdSucursal = ""; string InstruccionesExpeciales = ""; string Comision = ""; string MontoCuota = ""; string IdCuotaBallom = ""; string IdDatosSindicados = ""; string IdDestinoRecursos = ""; string DiaPago = ""; string IdDistribucionGracia = ""; string IdDividendo = ""; string EsEvitarFeriados = ""; string FechaInicioOperacion = ""; string FechaVencimientoOperacion = ""; string IdFilial = ""; string EsFondosPropios = ""; string PeriodoGraciaCapital = ""; string PeriodoGraciaInteres = ""; string IdLineaCredito = ""; string IdMoneda = ""; string MontoPrestamo = ""; string IdNaturalezaGasto = ""; string IdOrigenFondos = ""; string IdPeriodoCapital = ""; string IdPeriodoInteres = ""; string IdPeriodoReajuste = ""; string MontoPLAS = ""; string PlazoMeses = ""; string MontoPrimaSeguroDesempleo = ""; string MontoPrimaSeguroVida = ""; string IdProducto = ""; string IdPropositoOperacion = ""; string EsReajustable = ""; string IdSector = ""; string EsSindicado = ""; string PorcentajeTasaInteres = ""; string TipoAmortizacion = ""; string IdTipoPlazo = ""; string NumCuentaFormaPago = ""; string IdTipoOperacion = ""; string IdNormalORefinanciamiento = ""; string NoOperacion = ""; try { respuesta = new JsonCrearOperacionResponse(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { int? idClienteDeudor = null; int? idClienteCodeudor = null; Cliente _modelClienteDeudor = null; Cliente _modelClienteCodeudor = null; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 1"); Solicitud _modelSolicitud = (db.Solicitud .Include(e => e.Cotizacion) .Include(e => e.PropositoCredito) .Include("Cotizacion.EjecutivoCotizacion") .Include("Cotizacion.CondicionesTasaCotizacion") .Include("Cotizacion.SegurosCotizacion") .Include("Cotizacion.SegurosCotizacion.RubroSeguro") .Include(e => e.Solicitante) .Include(e => e.DataFaseII).Where(e => e.IdSolicitud == req.IdSolicitud)).FirstOrDefault(); Cotizacion _modelCotizacion = _modelSolicitud.Cotizacion; idClienteDeudor = _modelSolicitud.Solicitante.Where(e => e.IdTipoSolicitante == 1).Select(e => e.IdCliente).FirstOrDefault(); _modelClienteDeudor = db.Cliente .Include(e => e.DireccionCliente) .Where(e => e.IdCliente == idClienteDeudor).FirstOrDefault(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 2"); try { idClienteCodeudor = _modelSolicitud.Solicitante.Where(e => e.IdTipoSolicitante == 2).Select(e => e.IdCliente).FirstOrDefault(); if (idClienteCodeudor != null) { _modelClienteCodeudor = db.Cliente .Include(e => e.DireccionCliente) .Where(e => e.IdCliente == idClienteCodeudor).FirstOrDefault(); } } catch (Exception) { throw; } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 3"); DataFaseII _modelDataFase2 = _modelSolicitud.DataFaseII.FirstOrDefault(); if (_modelDataFase2 != null) NoOperacion = Convert.ToString(_modelDataFase2.NoOperacion); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 4"); DateTime dtFechaInicio = (DateTime)_modelDataFase2.FechaInicio; int nDiaPago = 0; try { nDiaPago = int.Parse(ConfigurationManager.AppSettings["Cartera.DiaPagoPrestamo"].ToString()); } catch (Exception) { nDiaPago = 8; } IdActividadEconomica = _modelSolicitud.PropositoCredito.IdActividadEconomica.ToString(); IdBanderaBaseCalendario = "E"; IdCiudad = _modelClienteDeudor.DireccionCliente.Where(e => e.IdTipoDireccion.Trim() == "DM").Select(e => e.IdCanton.ToString()).FirstOrDefault(); EnteDeudor = string.IsNullOrEmpty(_modelClienteDeudor.Ente) ? string.Empty : _modelClienteDeudor.Ente.ToString(); EnteCodeudor1 = ""; EnteCodeudor2 = ""; IdTipoCartera = "0"; CodigoOficial = _modelCotizacion.EjecutivoCotizacion.CodOficial.ToString(); IdSucursal = _modelSolicitud.IdSucursal.ToString(); InstruccionesExpeciales = _modelDataFase2.InstruccionesEspeciales; Comision = _modelCotizacion.PorcComision.ToString(); MontoCuota = _modelCotizacion.CuotaPrestamo.ToString(); IdCuotaBallom = "N"; IdDatosSindicados = "N"; IdDestinoRecursos = _modelSolicitud.PropositoCredito.IdDestino.ToString(); ; DiaPago = nDiaPago.ToString(); IdDistribucionGracia = "N"; IdDividendo = "M"; EsEvitarFeriados = "S"; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 5"); FechaInicioOperacion = _modelDataFase2.FechaInicio.Value.ToString("yyyy-MM-dd") + "T06:00:00.0000Z"; FechaVencimientoOperacion = ""; IdFilial = "1"; EsFondosPropios = "S"; switch (_modelCotizacion.IdTipoGracia) { case EnumGracia.NoAplica: PeriodoGraciaCapital = "0"; PeriodoGraciaInteres = "0"; break; case EnumGracia.EnCapital: PeriodoGraciaCapital = _modelCotizacion.PeriodoMesesGracia.ToString(); PeriodoGraciaInteres = "0"; break; case EnumGracia.EnInteres: PeriodoGraciaCapital = "0"; PeriodoGraciaInteres = _modelCotizacion.PeriodoMesesGracia.ToString(); break; case EnumGracia.EnSeguroAuto: PeriodoGraciaCapital = "0"; PeriodoGraciaInteres = "0"; break; case EnumGracia.EnInteresEnCapital: PeriodoGraciaCapital = _modelCotizacion.PeriodoMesesGracia.ToString(); PeriodoGraciaInteres = _modelCotizacion.PeriodoMesesGracia.ToString(); break; case EnumGracia.EnInteresEnCapitalEnSeguroAuto: PeriodoGraciaCapital = _modelCotizacion.PeriodoMesesGracia.ToString(); PeriodoGraciaInteres = _modelCotizacion.PeriodoMesesGracia.ToString(); break; default: PeriodoGraciaCapital = "0"; PeriodoGraciaInteres = "0"; break; } IdLineaCredito = ConfigurationManager.AppSettings["Cartera.LineaCredito"].ToString(); IdMoneda = _modelCotizacion.IdMoneda.ToString(); MontoPrestamo = _modelCotizacion.MontoPrestamo.ToString(); IdNaturalezaGasto = _modelSolicitud.PropositoCredito.IdNaturalezaGasto.ToString(); IdOrigenFondos = _modelSolicitud.PropositoCredito.IdOrigenRecursos.ToString(); ; IdPeriodoCapital = "1"; IdPeriodoInteres = "1"; IdPeriodoReajuste = "0"; MontoPLAS = "0"; PlazoMeses = _modelCotizacion.PeriodoMesesCredito.ToString(); MontoPrimaSeguroDesempleo = _modelCotizacion.SegurosCotizacion.Where(e => e.RubroSeguro.IdTipoRubroSeguro == 2).Select(e => e.Monto.ToString()).FirstOrDefault(); MontoPrimaSeguroVida = _modelCotizacion.SegurosCotizacion.Where(e => e.RubroSeguro.IdTipoRubroSeguro == 1).Select(e => e.Monto.ToString()).FirstOrDefault(); IdProducto = ConfigurationManager.AppSettings["Cartera.ProductoCredito"].ToString(); IdPropositoOperacion = _modelSolicitud.PropositoCredito.IdActividadEconomica.ToString(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 6"); EsReajustable = "E"; IdSector = ConfigurationManager.AppSettings["Cartera.SectorCredito"].ToString(); EsSindicado = "N"; PorcentajeTasaInteres = _modelCotizacion.CondicionesTasaCotizacion.Where(x => x.Periodo == 1).Select(x => (x.Spread + x.TasaReferencia).ToString()).FirstOrDefault(); TipoAmortizacion = "FRANCESA"; IdTipoPlazo = "M"; NumCuentaFormaPago = ""; IdTipoOperacion = _modelDataFase2.TipoOperacion.ToString(); IdNormalORefinanciamiento = "C"; //R= Refinanciamiento C=Creacion Normal NoOperacion = ""; //Numer oOperacion a Refinanciar log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 7"); string xmlPath = string.Format("{0}\\CrearOperacion.xml", ConfigurationManager.AppSettings["XmlPath"]); string xmlString = File.ReadAllText(xmlPath); xmlString = xmlString.Replace("", string.Format("{0}", IdActividadEconomica)); xmlString = xmlString.Replace("", string.Format("{0}", IdBanderaBaseCalendario)); xmlString = xmlString.Replace("", string.Format("{0}", IdCiudad)); xmlString = xmlString.Replace("", string.Format("{0}", EnteDeudor)); xmlString = xmlString.Replace("", string.Format("{0}", EnteCodeudor1)); xmlString = xmlString.Replace("", string.Format("{0}", EnteCodeudor2)); xmlString = xmlString.Replace("", string.Format("{0}", IdTipoCartera)); xmlString = xmlString.Replace("", string.Format("{0}", CodigoOficial)); xmlString = xmlString.Replace("", string.Format("{0}", IdSucursal)); xmlString = xmlString.Replace("", string.Format("{0}", InstruccionesExpeciales)); xmlString = xmlString.Replace("", string.Format("{0}", Comision)); xmlString = xmlString.Replace("", string.Format("{0}", MontoCuota)); xmlString = xmlString.Replace("", string.Format("{0}", IdCuotaBallom)); xmlString = xmlString.Replace("", string.Format("{0}", IdDatosSindicados)); xmlString = xmlString.Replace("", string.Format("{0}", IdDestinoRecursos)); xmlString = xmlString.Replace("", string.Format("{0}", DiaPago)); xmlString = xmlString.Replace("", string.Format("{0}", IdDistribucionGracia)); xmlString = xmlString.Replace("", string.Format("{0}", IdDividendo)); xmlString = xmlString.Replace("", string.Format("{0}", EsEvitarFeriados)); xmlString = xmlString.Replace("", string.Format("{0}", FechaInicioOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", FechaVencimientoOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", IdFilial)); xmlString = xmlString.Replace("", string.Format("{0}", EsFondosPropios)); xmlString = xmlString.Replace("", string.Format("{0}", PeriodoGraciaCapital)); xmlString = xmlString.Replace("", string.Format("{0}", PeriodoGraciaInteres)); xmlString = xmlString.Replace("", string.Format("{0}", IdLineaCredito)); xmlString = xmlString.Replace("", string.Format("{0}", IdMoneda)); xmlString = xmlString.Replace("", string.Format("{0}", MontoPrestamo)); xmlString = xmlString.Replace("", string.Format("{0}", IdNaturalezaGasto)); xmlString = xmlString.Replace("", string.Format("{0}", IdOrigenFondos)); xmlString = xmlString.Replace("", string.Format("{0}", IdPeriodoCapital)); xmlString = xmlString.Replace("", string.Format("{0}", IdPeriodoInteres)); xmlString = xmlString.Replace("", string.Format("{0}", IdPeriodoReajuste)); xmlString = xmlString.Replace("", string.Format("{0}", MontoPLAS)); xmlString = xmlString.Replace("", string.Format("{0}", PlazoMeses)); xmlString = xmlString.Replace("", string.Format("{0}", MontoPrimaSeguroDesempleo)); xmlString = xmlString.Replace("", string.Format("{0}", MontoPrimaSeguroVida)); xmlString = xmlString.Replace("", string.Format("{0}", IdProducto)); xmlString = xmlString.Replace("", string.Format("{0}", IdPropositoOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", EsReajustable)); xmlString = xmlString.Replace("", string.Format("{0}", IdSector)); xmlString = xmlString.Replace("", string.Format("{0}", EsSindicado)); xmlString = xmlString.Replace("", string.Format("{0}", PorcentajeTasaInteres)); xmlString = xmlString.Replace("", string.Format("{0}", TipoAmortizacion)); xmlString = xmlString.Replace("", string.Format("{0}", IdTipoPlazo)); xmlString = xmlString.Replace("", string.Format("{0}", NumCuentaFormaPago)); xmlString = xmlString.Replace("", string.Format("{0}", IdTipoOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", IdNormalORefinanciamiento)); xmlString = xmlString.Replace("", string.Format("{0}", NoOperacion)); //xmlString = xmlString.Replace("", string.Format("{0}", NoOperacion)); //xmlString = xmlString.Replace("", string.Format("{0}", FechaLiquidacionOperacion.Value.ToString("yyyy-MM-dd") + "T06:00:00.0000Z")); //xmlString = xmlString.Replace("", string.Format("{0}", NoGarantia)); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "8 -->" + xmlString); resp = interfaces.GenerarOperacionCompleta(new ServiciosCobisCarteraPrendario.GenerarOperacionCompletaRequest() { Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario.ToString(), NumOperacion = NoOperacion, Solicitud = req.IdSolicitud.ToString(), strXML = xmlString, Usuario = req.UserId }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta de la liquidacion en cobis. Por favor comuniquese con el Administrador del Sistema."); } MSXML2.DOMDocument xmlRespuesta = new DOMDocument(); xmlRespuesta.loadXML(resp.resultado); if (xmlRespuesta.documentElement.selectSingleNode("ERROR") != null) { throw new Exception(xmlRespuesta.documentElement.selectSingleNode("ERROR").text); } respuesta.NoOperacion = xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("num_operacion").text; respuesta.FechaInicioPrestamo = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fecha_inicio").text, 1); respuesta.FechaFinPrestamo = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fecha_vencim").text, 1); respuesta.FechaPrimerPagoCapital = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fe_1_pago_cap").text, 1); respuesta.FechaPrimerPagoInteres = StringToDateTime(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("fe_1_pago_int").text, 1); respuesta.NumCuotas = StringToInteger(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("num_cuotas").text); respuesta.PlazoEnDias = StringToInteger(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("plazo_dias").text); respuesta.NumeroOperacionesVigentes = StringToInteger(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("nu_ope_vigentes").text); respuesta.MontoDesembolso = StringToDecimal(xmlRespuesta.selectSingleNode("Resultado").childNodes[0].childNodes[0].childNodes[0].selectSingleNode("monto_desembolso").text); _modelDataFase2.NoOperacion = respuesta.NoOperacion; _modelDataFase2.FechaInicio = respuesta.FechaInicioPrestamo; _modelDataFase2.FechaFin = respuesta.FechaFinPrestamo; _modelDataFase2.FechaPrimerPagoCapital = respuesta.FechaPrimerPagoCapital; _modelDataFase2.FechaPrimerPagoInteres = respuesta.FechaPrimerPagoInteres; _modelDataFase2.NumCuotas = respuesta.NumCuotas; _modelDataFase2.PlazoEnDias = respuesta.PlazoEnDias; _modelDataFase2.NumOperacionesVigentes = respuesta.NumeroOperacionesVigentes; _modelDataFase2.MontoDesembolso = respuesta.MontoDesembolso; ActualizarDatosOperacion(_modelDataFase2); } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; respuesta.Alertas.Add(ex.Message); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region RegistrarTasascalonada [HttpPost] public JsonResponseBase RegistrarTasascalonada(JsonRegistrarTasaEscalonadaRequest req) { JsonResponseBase respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisCarteraPrendario.RegistrarTasaEscalonadaResponse resp = null; string _NumOperacion = string.Empty; string _Fecha = string.Empty; string _Porcentaje = string.Empty; string _Referencial = string.Empty; string _Signo = string.Empty; string _Spread = string.Empty; string _TasaMin = string.Empty; string _TasaMax = string.Empty; string _Periocidad = string.Empty; string _Observacion = string.Empty; int? _TipoTasa = null; try { respuesta = new JsonResponseBase(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { Solicitud _Solicitud = db.Solicitud .Include(s => s.Cotizacion) .Include("Cotizacion.CondicionesTasaCotizacion") .Include("Cotizacion.CondicionesTasaCotizacion.TipoTasaReferencia") .Where(s => s.IdSolicitud == req.IdSolicitud).FirstOrDefault(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 1"); Cotizacion _Cotizacion = _Solicitud.Cotizacion; string xmlPath = string.Format("{0}\\CrearTasaEscalonada.xml", ConfigurationManager.AppSettings["XmlPath"]); string xmlString = string.Empty; DateTime _fechaRegistro = (DateTime)req.FechaPrimerPago; bool _IsSoloTasaFija = false; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 2"); if (_Cotizacion.CondicionesTasaCotizacion.Count == 1) if ((int)_Cotizacion.CondicionesTasaCotizacion.First().IdTipoTasa == (int)EnumTipoTasa.FIJA) _IsSoloTasaFija = true; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 3"); var Ordenamiento = _Cotizacion.CondicionesTasaCotizacion.OrderBy(x => x.Periodo); foreach (CondicionesTasaCotizacion _CondicionTasaCotizacion in Ordenamiento) { string[] arrOperacion = new string[] { "I" }; //************************************************************* //No registra el primer periodo en el escalonamiento //ya que hereda las condiciones con que fue creada la operacion //************************************************************* if (_CondicionTasaCotizacion.Periodo != 1) { foreach (string _Operacion in arrOperacion) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 4=> Operacion: " + _Operacion); _NumOperacion = req.NoOperacion; _Fecha = _fechaRegistro.ToString("yyyy-MM-dd") + "T06:00:00.0000Z"; _Porcentaje = (_CondicionTasaCotizacion.Spread + _CondicionTasaCotizacion.TasaReferencia).ToString(); _Referencial = _CondicionTasaCotizacion.TipoTasaReferencia.Nemonico; _Signo = "+"; _Spread = _CondicionTasaCotizacion.Spread.ToString(); _TasaMin = _CondicionTasaCotizacion.TasaMinima.ToString(); _TasaMax = "100"; _TipoTasa = _CondicionTasaCotizacion.IdTipoTasa; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 4"); if (_CondicionTasaCotizacion.IdPeriodoReajuste.Trim() == EnumPeriodoReajuste.ANUAL.key) _Periocidad = EnumPeriodoReajuste.ANUAL.value.ToString(); if (_CondicionTasaCotizacion.IdPeriodoReajuste.Trim() == EnumPeriodoReajuste.MENSUAL.key) _Periocidad = EnumPeriodoReajuste.MENSUAL.value.ToString(); if (_CondicionTasaCotizacion.IdPeriodoReajuste.Trim() == EnumPeriodoReajuste.SEMESTRAL.key) _Periocidad = EnumPeriodoReajuste.SEMESTRAL.value.ToString(); if (_CondicionTasaCotizacion.IdPeriodoReajuste.Trim() == EnumPeriodoReajuste.TRIMESTRAL.key) _Periocidad = EnumPeriodoReajuste.TRIMESTRAL.value.ToString(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 6"); xmlString = File.ReadAllText(xmlPath); xmlString = xmlString.Replace("", string.Format("{0}", _Operacion)); xmlString = xmlString.Replace("", string.Format("{0}", _NumOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", _Fecha)); xmlString = xmlString.Replace("", string.Format("{0}", _Periocidad)); xmlString = xmlString.Replace("", string.Format("{0}", _Observacion)); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 7"); //********************************************************** //Si es solo tasa fija //********************************************************** if (_IsSoloTasaFija) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 8"); //********************************************************** //Envia a la interface el porcentaje de tasa fija //********************************************************** xmlString = xmlString.Replace("", string.Format("{0}", _Porcentaje)); //********************************************************** //Limpia de la trama los campos para tasa escalonada //********************************************************** xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); } else { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 9"); //********************************************************** //Si es tasa fija //********************************************************** if (_TipoTasa == (int)EnumTipoTasa.FIJA) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 10"); //********************************************************** //Envia a la interface el porcentaje de tasa fija //********************************************************** xmlString = xmlString.Replace("", string.Format("{0}", _Porcentaje)); //********************************************************** //Limpia de la trama los campos para tasa escalonada //********************************************************** xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); xmlString = xmlString.Replace("", string.Empty); } else { //********************************************************** //Si es tasa variable //********************************************************** log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 11"); //********************************************************** //Limpia de la trama el campo para tasa fija //Importante:Si hay periodo de fija va a incluirse dentro del escalonamiento //********************************************************** xmlString = xmlString.Replace("", string.Empty); //********************************************************** //Envia a la interface los campos para tasa escalonada //********************************************************** xmlString = xmlString.Replace("", string.Format("{0}", _Referencial)); xmlString = xmlString.Replace("", string.Format("{0}", _Signo)); xmlString = xmlString.Replace("", string.Format("{0}", _Spread)); xmlString = xmlString.Replace("", string.Format("{0}", _TasaMin)); xmlString = xmlString.Replace("", string.Format("{0}", _TasaMax)); } } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 12"); resp = interfaces.RegistrarTasaEscalonada(new ServiciosCobisCarteraPrendario.RegistrarTasaEscalonadaRequest() { Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario.ToString(), Solicitud = req.IdSolicitud.ToString(), strXML = xmlString, Usuario = req.UserId }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta del registro de tasa escalonada en cobis. Por favor comuniquese con el Administrador del Sistema."); } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 13"); } } //********************************************************** //Calcula la siguiente fecha a registrar de escalonamiento //********************************************************** _fechaRegistro = _fechaRegistro.AddMonths((int)_CondicionTasaCotizacion.PlazoMeses - (_CondicionTasaCotizacion.Periodo == 1 ? 1 : 0)); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 14"); } } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; respuesta.Alertas.Add(ex.Message); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region RegistrarCodeudor [HttpPost] public JsonResponseBase RegistrarCodeudor(JsonRegistrarTasaEscalonadaRequest req) { JsonResponseBase respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisCarteraPrendario.RegistrarCodeudorResponse resp = null; string _NumOperacion = string.Empty; string _EnteCodeudor = string.Empty; string _IdentificacionCodeudor = string.Empty; try { respuesta = new JsonResponseBase(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { Solicitud _Solicitud = db.Solicitud .Include(s => s.Solicitante) .Include(s => s.DataFaseII) .Include("Solicitante.Cliente") .Where(s => s.IdSolicitud == req.IdSolicitud).FirstOrDefault(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 1"); _Solicitud.AplicaIntegracionConCartera = _Solicitud.AplicaIntegracionConCartera.HasValue ? _Solicitud.AplicaIntegracionConCartera : false; if (_Solicitud.AplicaIntegracionConCartera.Value) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 2"); if (_Solicitud.DataFaseII != null & _Solicitud.DataFaseII.Count > 0) _NumOperacion = _Solicitud.DataFaseII.First().NoOperacion; else throw new Exception("No se pudo obtener el numero de operación, por favor contacte al Administrador del Sistema."); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 3"); string xmlPath = string.Format("{0}\\CrearCodeudor.xml", ConfigurationManager.AppSettings["XmlPath"]); string xmlString = string.Empty; foreach (Solicitante _Solicitante in _Solicitud.Solicitante) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 4"); if (_Solicitante.IdTipoSolicitante == 2) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 5"); _EnteCodeudor = _Solicitante.Cliente.Ente; _IdentificacionCodeudor = _Solicitante.Cliente.Identificacion; xmlString = File.ReadAllText(xmlPath); xmlString = xmlString.Replace("", string.Format("{0}", _NumOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", _EnteCodeudor)); xmlString = xmlString.Replace("", string.Format("{0}", _IdentificacionCodeudor)); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 6=>" + xmlString); resp = interfaces.RegistrarCodeudor(new ServiciosCobisCarteraPrendario.RegistrarCodeudorRequest() { Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario.ToString(), Solicitud = req.IdSolicitud.ToString(), strXML = xmlString, Usuario = req.UserId }); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 7"); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 8"); if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta del registro del codeudor en cobis. Por favor comuniquese con el Administrador del Sistema."); } } } } } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Falg 9"); respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; respuesta.Alertas.Add(ex.Message); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region RegistrarSeguro [HttpPost] public JsonResponseBase RegistrarSeguro(JsonRegistrarTasaEscalonadaRequest req) { JsonResponseBase respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisCarteraPrendario.RegistrarSeguroResponse resp = null; string _Aseguradora = string.Empty; string _NumOperacion = string.Empty; string _TipoRubro = string.Empty; string _Moneda = string.Empty; string _fechaConst = string.Empty; string _fechaFin = string.Empty; string _frecuencia = string.Empty; string _monto = string.Empty; string _sucursal = string.Empty; string _codigoExterno = string.Empty; string _porcentajeRecarVida = "0"; string _porcentajeRecarItp = "0"; try { respuesta = new JsonResponseBase(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { Solicitud _Solicitud = db.Solicitud .Include(s => s.Cotizacion) .Include(s => s.DataFaseII) .Include("Cotizacion.SegurosCotizacion") .Include("Cotizacion.SegurosCotizacion.RubroSeguro") .Where(s => s.IdSolicitud == req.IdSolicitud).FirstOrDefault(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 1"); Cotizacion _Cotizacion = _Solicitud.Cotizacion; _Solicitud.AplicaIntegracionConCartera = _Solicitud.AplicaIntegracionConCartera.HasValue ? _Solicitud.AplicaIntegracionConCartera : false; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 2"); if (_Solicitud.AplicaIntegracionConCartera.Value) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 3"); if (_Solicitud.DataFaseII != null & _Solicitud.DataFaseII.Count > 0) _NumOperacion = _Solicitud.DataFaseII.First().NoOperacion; else throw new Exception("No se pudo obtener el numero de operación, por favor contacte al Administrador del Sistema."); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 4"); foreach (SegurosCotizacion _SegCotizacion in _Cotizacion.SegurosCotizacion) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 5"); if (_SegCotizacion.RubroSeguro.IdTipoRubroSeguro != (int)EnumTipoRubroSeguro.Auto) { log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 6"); string xmlString = string.Empty; string xmlPath = string.Format("{0}\\RegistrarSeguro.xml", ConfigurationManager.AppSettings["XmlPath"]); xmlString = File.ReadAllText(xmlPath); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 7"); _Aseguradora = string.Format("00{0}", _SegCotizacion.RubroSeguro.IdAseguradora); switch (_SegCotizacion.RubroSeguro.IdTipoRubroSeguro) { case (int)EnumTipoRubroSeguro.Desempleo: _TipoRubro = "D"; break; case (int)EnumTipoRubroSeguro.Vida: _TipoRubro = "V"; break; } log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 8"); _Moneda = _Cotizacion.IdMoneda.ToString(); _fechaConst = _Solicitud.DataFaseII.First().FechaRegeneracion.Value.ToString("yyyy-MM-dd") + "T06:00:00.0000Z"; _fechaFin = _Solicitud.DataFaseII.First().FechaFin.Value.ToString("yyyy-MM-dd") + "T06:00:00.0000Z"; _frecuencia = "M"; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 9"); _monto = _SegCotizacion.Monto.ToString(); _sucursal = _Solicitud.IdSucursal.ToString(); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 10"); _codigoExterno = ""; _porcentajeRecarVida = "0"; _porcentajeRecarItp = "0"; xmlString = xmlString.Replace("", string.Format("{0}", _Aseguradora)); xmlString = xmlString.Replace("", string.Format("{0}", _NumOperacion)); xmlString = xmlString.Replace("", string.Format("{0}", _TipoRubro)); xmlString = xmlString.Replace("", string.Format("{0}", _Moneda)); xmlString = xmlString.Replace("", string.Format("{0}", _fechaConst)); xmlString = xmlString.Replace("", string.Format("{0}", _fechaFin)); xmlString = xmlString.Replace("", string.Format("{0}", _frecuencia)); xmlString = xmlString.Replace("", string.Format("{0}", _monto)); xmlString = xmlString.Replace("", string.Format("{0}", _sucursal)); xmlString = xmlString.Replace("", string.Format("{0}", _codigoExterno)); xmlString = xmlString.Replace("", string.Format("{0}", _porcentajeRecarVida)); xmlString = xmlString.Replace("", string.Format("{0}", _porcentajeRecarItp)); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 11 => " + xmlString); resp = interfaces.RegistrarSeguro(new ServiciosCobisCarteraPrendario.RegistrarSeguroRequest() { Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario.ToString(), Solicitud = req.IdSolicitud.ToString(), strXML = xmlString, Usuario = req.UserId, TipoSeguro = _TipoRubro }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta del registro seguros en cobis. Por favor comuniquese con el Administrador del Sistema."); } } } } } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; respuesta.Alertas.Add(ex.Message); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region ObtenerCalculoEndeudamiento [HttpGet] public JsonCalculoEndeudamientoResponse ObtenerCalculoEndeudamiento(int IdSolicitud, int IdCliente, int IdMoneda, decimal TipoCambio) { #region Variables/Objetos ReferenciaDeudaAPIController refDeudas = null; InfoLaboralAPIController infoLaboral = null; JsonCalculoEndeudamientoResponse respuesta = null; decimal dblCuotaPrestamo = 0; decimal dblTotalCompromisosCliente = 0; decimal dblTotalIngresosNetosCliente = 0; #endregion try { #region Inicializa Objetos respuesta = new JsonCalculoEndeudamientoResponse(); refDeudas = new ReferenciaDeudaAPIController(); infoLaboral = new InfoLaboralAPIController(); #endregion #region ObtenerDeudasCliente var respDeudasCliente = refDeudas.ObtenerDeudasCliente(IdSolicitud, IdCliente, IdMoneda, TipoCambio, true); if (respDeudasCliente.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respDeudasCliente.DescripcionRespuesta); } dblTotalCompromisosCliente = (decimal)respDeudasCliente.TotalDeudas; #endregion #region ObtenerInfoIngresosClinte var respInfoIngresos = infoLaboral.ObtenerInfoIngresosClinte(IdSolicitud, IdCliente, TipoCambio, IdMoneda, true); if (respInfoIngresos.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respInfoIngresos.DescripcionRespuesta); } dblTotalIngresosNetosCliente = respInfoIngresos.TotalIngresosNetos; #endregion #region ObtenerCuotaPrestamo using (PrendarioContext db = new PrendarioContext()) { Solicitud _modelSolicitud = db.Solicitud .Where(c => c.IdSolicitud == IdSolicitud) .Include(c => c.Cotizacion) .Include(c => c.Cotizacion.CondicionesTasaCotizacion) .FirstOrDefault(); #region Ticket #2016062410001191 //************************************************************************ //BMU - 28-07-2016 - Ticket #2016062410001191 //Modificación para obtener la cuota del ultimo periodo de tasa escalonada //************************************************************************ //CondicionesTasaCotizacion UltimoPeriodoCondicionesTasa = _modelSolicitud.Cotizacion.CondicionesTasaCotizacion.OrderByDescending(x => x.Periodo).FirstOrDefault(); //dblCuotaPrestamo = Convert.ToDecimal(new CotizacionAPIController().CalculaCuotaBase((double)((UltimoPeriodoCondicionesTasa.TasaReferencia + UltimoPeriodoCondicionesTasa.Spread) / 100), _modelSolicitud.Cotizacion.PeriodoMesesCredito.Value, (double)_modelSolicitud.Cotizacion.MontoPrestamo)); //************************************************************************ //BMU - 28-07-2016 - Ticket #2016062410001191 //Modificación para obtener la cuota del ultimo periodo de tasa escalonada //************************************************************************ dblCuotaPrestamo = _modelSolicitud.Cotizacion.CuotaPrestamo == null ? 0 : _modelSolicitud.Cotizacion.CuotaPrestamo.Value; //************************************************************************ #endregion } #endregion #region Calculo Endeudamiento respuesta.Endeudamiento = Math.Round(((dblTotalCompromisosCliente + dblCuotaPrestamo) / dblTotalIngresosNetosCliente), 6); #endregion #region Calculo Cuota Ingreso var respCalcCuotaIngreso = ObtenerCalculoCuotaIngreso(dblCuotaPrestamo, dblTotalIngresosNetosCliente); if (respCalcCuotaIngreso.CodigoRespuesta != "EXITOSO") throw new Exception(respCalcCuotaIngreso.DescripcionRespuesta); respuesta.CuotaIngreso = respCalcCuotaIngreso.CuotaIngreso; #endregion respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } public JsonCalculoEndeudamientoResponse ObtenerCalculoEndeudamiento(int IdSolicitud, int IdCliente, int IdMoneda, decimal TipoCambio, decimal CuotaPrestamo, decimal TotalIngresosNetosCliente) { #region Variables/Objetos ReferenciaDeudaAPIController refDeudas = null; InfoLaboralAPIController infoLaboral = null; JsonCalculoEndeudamientoResponse respuesta = null; decimal decTotalCompromisosCliente = 0; #endregion try { #region Inicializa Objetos respuesta = new JsonCalculoEndeudamientoResponse(); refDeudas = new ReferenciaDeudaAPIController(); infoLaboral = new InfoLaboralAPIController(); #endregion #region ObtenerDeudasCliente var respDeudasCliente = refDeudas.ObtenerDeudasCliente(IdSolicitud, IdCliente, IdMoneda, TipoCambio, true); if (respDeudasCliente.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respDeudasCliente.DescripcionRespuesta); } decTotalCompromisosCliente = (decimal)respDeudasCliente.TotalDeudas; #endregion #region Calculo Endeudamiento respuesta.Endeudamiento = Math.Round(((decTotalCompromisosCliente + CuotaPrestamo) / TotalIngresosNetosCliente), 6); #endregion #region Calculo Cuota Ingreso var respCalcCuotaIngreso = ObtenerCalculoCuotaIngreso(CuotaPrestamo, TotalIngresosNetosCliente); if (respCalcCuotaIngreso.CodigoRespuesta != "EXITOSO") throw new Exception(respCalcCuotaIngreso.DescripcionRespuesta); respuesta.CuotaIngreso = respCalcCuotaIngreso.CuotaIngreso; #endregion respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region ObtenerCalculoCuotaIngreso [HttpGet] public JsonCalculoCuotaIngresoResponse ObtenerCalculoCuotaIngreso(int IdSolicitud, int IdCliente, int IdMoneda, decimal TipoCambio) { #region Variables/Objetos InfoLaboralAPIController infoLaboral = null; JsonCalculoCuotaIngresoResponse respuesta = null; decimal dblCuotaPrestamo = 0; decimal dblTotalIngresosNetosCliente = 0; #endregion try { #region Inicializa Objetos respuesta = new JsonCalculoCuotaIngresoResponse(); infoLaboral = new InfoLaboralAPIController(); #endregion #region ObtenerInfoIngresosClinte var respInfoIngresos = infoLaboral.ObtenerInfoIngresosClinte(IdSolicitud, IdCliente, TipoCambio, IdMoneda, true); if (respInfoIngresos.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respInfoIngresos.DescripcionRespuesta); } dblTotalIngresosNetosCliente = respInfoIngresos.TotalIngresosNetos; #endregion #region ObtenerCuotaPrestamo using (PrendarioContext db = new PrendarioContext()) { Solicitud _modelSolicitud = db.Solicitud .Where(c => c.IdSolicitud == IdSolicitud) .Include(c => c.Cotizacion) .Include(c => c.Cotizacion.CondicionesTasaCotizacion) .FirstOrDefault(); #region Ticket #2016062410001191 //************************************************************************ //BMU - 28-07-2016 - Ticket #2016062410001191 //Modificación para obtener la cuota del ultimo periodo de tasa escalonada //************************************************************************ //CondicionesTasaCotizacion UltimoPeriodoCondicionesTasa = _modelSolicitud.Cotizacion.CondicionesTasaCotizacion.OrderByDescending(x => x.Periodo).FirstOrDefault(); //dblCuotaPrestamo = Convert.ToDecimal(new CotizacionAPIController().CalculaCuotaBase((double)((UltimoPeriodoCondicionesTasa.TasaReferencia + UltimoPeriodoCondicionesTasa.Spread) / 100), _modelSolicitud.Cotizacion.PeriodoMesesCredito.Value, (double)_modelSolicitud.Cotizacion.MontoPrestamo)); //************************************************************************ //BMU - 28-07-2016 - Ticket #2016062410001191 //Modificación para obtener la cuota del ultimo periodo de tasa escalonada //************************************************************************ dblCuotaPrestamo = _modelSolicitud.Cotizacion.CuotaPrestamo == null ? 0 : _modelSolicitud.Cotizacion.CuotaPrestamo.Value; //************************************************************************ #endregion } #endregion #region CalculoCuotaIngreso respuesta.CuotaIngreso = Math.Round((dblCuotaPrestamo / dblTotalIngresosNetosCliente), 6); #endregion respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } public JsonCalculoCuotaIngresoResponse ObtenerCalculoCuotaIngreso(decimal CuotaPrestamo, decimal TotalIngresosNetosCliente) { #region Variables/Objetos JsonCalculoCuotaIngresoResponse respuesta = null; #endregion try { #region Inicializa Objetos respuesta = new JsonCalculoCuotaIngresoResponse(); #endregion #region CalculoCuotaIngreso respuesta.CuotaIngreso = Math.Round((CuotaPrestamo / TotalIngresosNetosCliente), 6); #endregion respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region ConsultarOficialNombre [HttpGet] public JsonConsultarOficialNombreResponse ConsultarOficialNombre(int IdSucursal, string NombreOficial, string Proceso, string Usuario) { InterfacesAPIController interfaces = null; JsonConsultarOficialNombreResponse respuesta = null; MSXML2.DOMDocument xmlRespuesta = new DOMDocument(); try { respuesta = new JsonConsultarOficialNombreResponse(); respuesta.oficiales = new List(); interfaces = new InterfacesAPIController(); #region ObtenerInfoOficiales var respOficiales = interfaces.ConsultarOficialNombre(new ConsultarOficialNombreRequest() { CoSucursal = IdSucursal.ToString(), NombreOficial = NombreOficial, Proceso = ServiciosCobisConsultaGeneral.EnumeradorProcesoUltimus.PrestamoPrendario, UserName = Usuario }); if (respOficiales.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respOficiales.errMessage); } #endregion if (string.IsNullOrEmpty(respOficiales.resultado)) { throw new Exception("No se pudo recuperar el resultado de la consulta de oficiles."); } xmlRespuesta.loadXML(respOficiales.resultado); if (xmlRespuesta.selectSingleNode("//Resultado/Oficiales") != null) { foreach (MSXML2.IXMLDOMNode nodoOficial in xmlRespuesta.selectSingleNode("//Resultado/Oficiales").childNodes) { JsonConsultarOficialNombre oficial = new JsonConsultarOficialNombre() { codigo = nodoOficial.selectSingleNode("CODIGO").text, descripcion = nodoOficial.selectSingleNode("NOMBRE").text, login = nodoOficial.selectSingleNode("LOGIN").text }; respuesta.oficiales.Add(oficial); } } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region ObtenerNivelCapacidadPagoDeudor [HttpGet] public JsonCalculoNivelCapacidadPagoResponse ObtenerNivelCapacidadPagoDeudor(int IdSolicitud, int IdCliente, int IdMoneda, decimal TipoCambio) { InterfacesAPIController oInterface = null; InfoLaboralAPIController infoLaboral = null; JsonCalculoNivelCapacidadPagoResponse respuesta = null; decimal decTotalIngresosNetosColones = 0; decimal decTotalIngresosNetosDolares = 0; decimal decEndeudamiento = 0; try { respuesta = new JsonCalculoNivelCapacidadPagoResponse(); oInterface = new InterfacesAPIController(); infoLaboral = new InfoLaboralAPIController(); #region ObtenerInfoIngresosCliente var respInfoIngresos = infoLaboral.ObtenerInfoIngresosClinte(IdSolicitud, IdCliente, TipoCambio, IdMoneda, true); if (respInfoIngresos.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respInfoIngresos.DescripcionRespuesta); } decTotalIngresosNetosColones = respInfoIngresos.TotalIngresosNetosColones; decTotalIngresosNetosDolares = respInfoIngresos.TotalIngresosNetosDolares; #endregion var respEndeudamiento = this.ObtenerCalculoEndeudamiento(IdSolicitud, IdCliente, IdMoneda, TipoCambio); if (respEndeudamiento.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respEndeudamiento.DescripcionRespuesta); } decEndeudamiento = respEndeudamiento.Endeudamiento; var resp = oInterface.ObtenerNivelCapacidadPagoDeudor(new ObtenerNivelCapacidadPagoDeudorRequest() { IdMoneda = IdMoneda, IngresoNetoColones = (double)decTotalIngresosNetosColones, IngresoNetoDolares = (double)decTotalIngresosNetosDolares, PorcEndeudamiento = decEndeudamiento, Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario, TasaCambio = (double)TipoCambio }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } respuesta.NivelCapacidadPago = resp.NivelCapacidadPago; respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region ClasificaGeneradorMoneda [HttpGet] public JsonClasificaGeneradorMonedaResponse ClasificaGeneradorMoneda(int IdSolicitud, int IdCliente, string DescripcionMoneda, decimal TipoCambio) { InterfacesAPIController oInterface = null; InfoLaboralAPIController infoLaboral = null; JsonClasificaGeneradorMonedaResponse respuesta = null; decimal decTotalIngresosNetosColones = 0; decimal decTotalIngresosNetosDolares = 0; decimal decCuotaPrestamo = 0; try { respuesta = new JsonClasificaGeneradorMonedaResponse(); oInterface = new InterfacesAPIController(); infoLaboral = new InfoLaboralAPIController(); #region ObtenerInfoIngresosCliente var respInfoIngresos = infoLaboral.ObtenerInfoIngresosClinte(IdSolicitud, IdCliente, TipoCambio, null, true); if (respInfoIngresos.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(respInfoIngresos.DescripcionRespuesta); } decTotalIngresosNetosColones = respInfoIngresos.TotalIngresosNetosColones; decTotalIngresosNetosDolares = respInfoIngresos.TotalIngresosNetosDolares; #endregion #region CuotaPrestamo using (PrendarioContext db = new PrendarioContext()) { Solicitud _modelSolicitud = db.Solicitud.Include(c => c.Cotizacion).Where(c => c.IdSolicitud == IdSolicitud).FirstOrDefault(); decCuotaPrestamo = _modelSolicitud.Cotizacion.CuotaPrestamo == null ? 0 : _modelSolicitud.Cotizacion.CuotaPrestamo.Value; } #endregion var resp = oInterface.ClasificaGeneradorMoneda(new ClasificaGeneradorMonedaRequest() { CuotaPrestamo = decCuotaPrestamo.ToString(), IdCliente = IdCliente.ToString(), IdSolicitud = IdSolicitud.ToString(), Moneda = DescripcionMoneda, Proceso = WCFServiciosGenerales.EnumeradorProcesoUltimus.PrestamoPrendario, TasaCambio = TipoCambio.ToString(), TotalIngresoNetoColones = decTotalIngresosNetosColones.ToString(), TotalIngresoNetoDolares = decTotalIngresosNetosDolares.ToString(), }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } respuesta.CategoriaGenerador = resp.CategoriaGenerador; respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion #region ObtenerRubroSeguro private List ObtenerRubroSeguro(EnumTipoRubroSeguro enumTipoRubroSeguro, string filtro) { List ret = new List(); List list = new List(); using (PrendarioContext db = new PrendarioContext()) { if (string.IsNullOrWhiteSpace(filtro)) list = db.RubroSeguro.Where(e => e.IdTipoRubroSeguro == (int)enumTipoRubroSeguro && e.Estado == true).ToList(); else list = db.RubroSeguro.Where(e => e.Descripcion.Trim().ToLower().Contains(filtro.Trim().ToLower()) == true && e.IdTipoRubroSeguro == (int)enumTipoRubroSeguro && e.Estado == true).ToList(); foreach (var ele in list) { JsonCatalogos catalogo = new JsonCatalogos(); catalogo.codigo = ele.IdRubroSeguro.ToString().Trim(); catalogo.descripcion = ele.Descripcion.ToString().Trim(); ret.Add(catalogo); } } return ret; } #endregion #region ObtenerFechaProcesoCobis [HttpPost] public JsonFechaProcesoCobis ObtenerFechaProcesoCobis(JsonRegistrarTasaEscalonadaRequest req) { JsonFechaProcesoCobis respuesta = null; InterfacesAPIController interfaces = null; ServiciosCobisConsultaGeneral.ConsultarFechaProcesoCobisResponse resp = null; try { respuesta = new JsonFechaProcesoCobis(); interfaces = new InterfacesAPIController(); using (PrendarioContext db = new PrendarioContext()) { resp = interfaces.ConsultarFechaProcesoCobis(new ServiciosCobisConsultaGeneral.ConsultarFechaProcesoCobisRequest() { Proceso = ServiciosCobisConsultaGeneral.EnumeradorProcesoUltimus.PrestamoPrendario, UserName = req.UserId }); if (resp.errCode == TipoCodigoRespuesta.ERROR.ToString()) { throw new Exception(resp.errMessage); } if (string.IsNullOrEmpty(resp.resultado)) { throw new Exception("No se pudo obtener la respuesta del registro seguros en cobis. Por favor comuniquese con el Administrador del Sistema."); } respuesta.FechaProceso = resp.FechaProceso; } respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); respuesta.DescripcionRespuesta = ex.Message; respuesta.Alertas.Add(ex.Message); log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex); } return respuesta; } #endregion } }