using System; using System.Collections.Generic; using System.Linq; using System.Web.Http; using ULA.Cathay.Credito.Json; using ULA.Cathay.CreditoModel.Credito; using ULA.Cathay.CreditoModel.DAL.Credito; using ULA.Cathay.CreditoModel.Entidades; using Ultimus.Interfaces; using Ultimus.Interfaces.UltimusIntegration; using Ultimus.Utilitarios; namespace ULA.Cathay.Credito.ControllersWebApi.Formalizacion { public class EjecutarDesembolsoAPIController : ApiController { UltimusLogs logs = new UltimusLogs("EjecutarDesembolsoAPIController"); public EjecutarDesembolsoAPIController() { GlobalAPIController.SetRegionalConfig(); } #region InsertarActualizar [HttpPost] public BaseJson InsertarActualizar(FormalizacionJSON model) { BaseJson respuesta = new BaseJson(); DatosGeneralesFormalizacionDAL DatosGeneralesFormalizacionDAL = new DatosGeneralesFormalizacionDAL(); BitacoraControlDAL BitacoraContlDal = new BitacoraControlDAL(); try { DatosGeneralesFormalizacionDAL.InsertarActualizar(model.DatosGeneralesFormalizacion); #region BitacoraControl if (model.BitacoraControl != null && model.BitacoraControl.Count > 0) BitacoraContlDal.InsertarActualizar(model.BitacoraControl.ToList()); #endregion respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString(); } catch (Exception ex) { logs.Error(ex); respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); return respuesta; } return respuesta; } #endregion #region ObtenerDatos [HttpGet] public FormalizacionJSON ObtenerDatos(int IdSolicitud, int Incidente) { FormalizacionJSON respuesta = new FormalizacionJSON(); List ListaEstructuraOC = null; List ListaUserEmail = null; EnvioCorreoAPIController CorreoAPI = new EnvioCorreoAPIController(); DatosGeneralesFormalizacionDAL DatosGeneralesFormalizacionDAL = new DatosGeneralesFormalizacionDAL(); List ObjEmailCliente = new List(); EmailClienteDAL ObjEmailClienteDAL = new EmailClienteDAL(); SolicitanteDAL SolicitanteDAL = new SolicitanteDAL(); List listaSolicitante = new List(); Cliente Cliente = new Cliente(); Solicitante SolicitantePrincipal = new Solicitante(); BitacoraDocumentosFormalizacion BitacoraDocumentosFormalizacion = new BitacoraDocumentosFormalizacion(); try { respuesta.DatosGeneralesFormalizacion = DatosGeneralesFormalizacionDAL.Obtener(IdSolicitud, Incidente); listaSolicitante = SolicitanteDAL.Obtener(IdSolicitud); SolicitantePrincipal = listaSolicitante.Where(x => x.EsPrincipal == true).FirstOrDefault(); respuesta.Participantes = new List(); BitacoraDocumentosFormalizacion.Incident = Incidente; BitacoraDocumentosFormalizacion.IdSolicitud = IdSolicitud; BitacoraDocumentosFormalizacion.IdProceso = respuesta.DatosGeneralesFormalizacion.IdProceso; respuesta.BitacoraDocumentosFormalizacion = new BitacoraDocumentosFormalizacionDAL().Obtener(BitacoraDocumentosFormalizacion); ListaEstructuraOC = new EstructuraOrgChartDAL().Obtener(EnumRolFuncional.Tesoreria, null); if (ListaEstructuraOC != null && ListaEstructuraOC.Count > 0) { foreach (var lista in ListaEstructuraOC) { if (!string.IsNullOrEmpty(lista.Name)) { ListaUserEmail = CorreoAPI.ObtenerCorreos(lista.Name, Convert.ToInt32(lista.IdTipoEstructuraOrgChart)); foreach (UltimusUser Email in ListaUserEmail) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.EmailAddress)) Participante.Correo = Email.EmailAddress; if (!string.IsNullOrEmpty(Email.strUserFullName)) Participante.NombreParticipante = Email.strUserFullName; Participante.Grupo = "Tesorería"; Participante.Notificacion = "1"; if (!string.IsNullOrEmpty(Email.EmailAddress) && !string.IsNullOrEmpty(Email.strUserFullName)) respuesta.Participantes.Add(Participante); } } } } ListaEstructuraOC = new EstructuraOrgChartDAL().Obtener(EnumRolFuncional.ServicioInternacional, null); if (ListaEstructuraOC != null && ListaEstructuraOC.Count > 0) { foreach (var lista in ListaEstructuraOC) { if (!string.IsNullOrEmpty(lista.Name)) { ListaUserEmail = CorreoAPI.ObtenerCorreos(lista.Name, Convert.ToInt32(lista.IdTipoEstructuraOrgChart)); foreach (UltimusUser Email in ListaUserEmail) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.EmailAddress)) Participante.Correo = Email.EmailAddress; if (!string.IsNullOrEmpty(Email.strUserFullName)) Participante.NombreParticipante = Email.strUserFullName; Participante.Grupo = "Internacional"; Participante.Notificacion = "1"; if (!string.IsNullOrEmpty(Email.EmailAddress) && !string.IsNullOrEmpty(Email.strUserFullName)) respuesta.Participantes.Add(Participante); } } } } if (SolicitantePrincipal.Cliente.EmailCliente != null || SolicitantePrincipal.Cliente.EmailCliente.Count > 0) { string nombre = SolicitantePrincipal.Cliente.IdTipoCliente == 1 ? SolicitantePrincipal.Cliente.PrimerNombre + " " + SolicitantePrincipal.Cliente.PrimerApellido + " " + SolicitantePrincipal.Cliente.SegundoApellido : SolicitantePrincipal.Cliente.RazonSocial; SolicitantePrincipal.Cliente.EmailCliente = new EmailClienteDAL().Obtener(SolicitantePrincipal.Cliente.IdCliente); foreach (EmailCliente Email in SolicitantePrincipal.Cliente.EmailCliente) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.Email)) Participante.Correo = Email.Email; Participante.NombreParticipante = nombre; Participante.Grupo = "Cliente"; Participante.Notificacion = "2"; if (!string.IsNullOrEmpty(Email.Email) && !string.IsNullOrEmpty(nombre)) respuesta.Participantes.Add(Participante); } } ListaEstructuraOC = new EstructuraOrgChartDAL().Obtener(EnumRolFuncional.Negocios, null); if (ListaEstructuraOC != null && ListaEstructuraOC.Count > 0) { foreach (var lista in ListaEstructuraOC) { if (!string.IsNullOrEmpty(lista.Name)) { ListaUserEmail = CorreoAPI.ObtenerCorreos(lista.Name, Convert.ToInt32(lista.IdTipoEstructuraOrgChart)); foreach (UltimusUser Email in ListaUserEmail) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.EmailAddress)) Participante.Correo = Email.EmailAddress; if (!string.IsNullOrEmpty(Email.strUserFullName)) Participante.NombreParticipante = Email.strUserFullName; Participante.Grupo = "Negocios"; Participante.Notificacion = "2"; if (!string.IsNullOrEmpty(Email.EmailAddress) && !string.IsNullOrEmpty(Email.strUserFullName)) respuesta.Participantes.Add(Participante); } } } } ListaEstructuraOC = new EstructuraOrgChartDAL().Obtener(EnumRolFuncional.OperacionesCrediticias, null); if (ListaEstructuraOC != null && ListaEstructuraOC.Count > 0) { foreach (var lista in ListaEstructuraOC) { if (!string.IsNullOrEmpty(lista.Name)) { ListaUserEmail = CorreoAPI.ObtenerCorreos(lista.Name, Convert.ToInt32(lista.IdTipoEstructuraOrgChart)); foreach (UltimusUser Email in ListaUserEmail) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.EmailAddress)) Participante.Correo = Email.EmailAddress; if (!string.IsNullOrEmpty(Email.strUserFullName)) Participante.NombreParticipante = Email.strUserFullName; Participante.Grupo = "Operaciones crediticias"; Participante.Notificacion = "2"; if (!string.IsNullOrEmpty(Email.EmailAddress) && !string.IsNullOrEmpty(Email.strUserFullName)) respuesta.Participantes.Add(Participante); } } } } ListaEstructuraOC = new EstructuraOrgChartDAL().Obtener(EnumRolFuncional.DescuentoFacturas, null); if (ListaEstructuraOC != null && ListaEstructuraOC.Count > 0) { foreach (var lista in ListaEstructuraOC) { if (!string.IsNullOrEmpty(lista.Name)) { ListaUserEmail = CorreoAPI.ObtenerCorreos(lista.Name, Convert.ToInt32(lista.IdTipoEstructuraOrgChart)); foreach (UltimusUser Email in ListaUserEmail) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.EmailAddress)) Participante.Correo = Email.EmailAddress; if (!string.IsNullOrEmpty(Email.strUserFullName)) Participante.NombreParticipante = Email.strUserFullName; Participante.Grupo = "Descuento de facturas"; Participante.Notificacion = "2"; if (!string.IsNullOrEmpty(Email.EmailAddress) && !string.IsNullOrEmpty(Email.strUserFullName)) respuesta.Participantes.Add(Participante); } } } } ListaEstructuraOC = new EstructuraOrgChartDAL().Obtener(EnumRolFuncional.OperacionesBancarias, null); if (ListaEstructuraOC != null && ListaEstructuraOC.Count > 0) { foreach (var lista in ListaEstructuraOC) { if (!string.IsNullOrEmpty(lista.Name)) { ListaUserEmail = CorreoAPI.ObtenerCorreos(lista.Name, Convert.ToInt32(lista.IdTipoEstructuraOrgChart)); foreach (UltimusUser Email in ListaUserEmail) { ParticipantesJSON Participante = new ParticipantesJSON(); if (!string.IsNullOrEmpty(Email.EmailAddress)) Participante.Correo = Email.EmailAddress; if (!string.IsNullOrEmpty(Email.strUserFullName)) Participante.NombreParticipante = Email.strUserFullName; Participante.Grupo = "Operaciones Bancarias"; Participante.Notificacion = "3"; if (!string.IsNullOrEmpty(Email.EmailAddress) && !string.IsNullOrEmpty(Email.strUserFullName)) respuesta.Participantes.Add(Participante); } } } } } catch (Exception ex) { logs.Error(ex); return respuesta = null; } return respuesta; } #endregion #region EnviarNotificacion [HttpPost] public BaseJson EnviarNotificacionTesoreriaInternacional(FormalizacionJSON model) { BaseJson respuesta = new BaseJson(); CorreosAutomaticosPendientes Correo = new CorreosAutomaticosPendientes(); EnvioCorreoAPIController CorreoAPI = new EnvioCorreoAPIController(); Etapas etapa = new Etapas(); EtapasDAL EtapaDAL = new EtapasDAL(); try { etapa = EtapaDAL.ObtenerEtapa(model.UltimusStep); Correo.IdCorreo = 0; Correo.IdSolicitud = model.DatosGeneralesFormalizacion.IdSolicitud; Correo.IdEtapa = etapa.IdEtapa; Correo.IdProceso = model.DatosGeneralesFormalizacion.IdProceso; Correo.Incident = model.DatosGeneralesFormalizacion.Incident; switch (model.DatosGeneralesFormalizacion.IdFormaDesembolso) { case 1: Correo.NombreFiltroCorreo = "NotificarTesoreriaCheque"; break; case 2: Correo.NombreFiltroCorreo = "NotificarTesoreriaSinpe"; break; case 4: Correo.NombreFiltroCorreo = "NotiTranferenciaInternacional"; break; case 5: Correo.NombreFiltroCorreo = "NotiCancelacionCartaCredito"; break; case 6: Correo.NombreFiltroCorreo = "NotiAperturaCartaCredito"; break; } Correo.UserID = model.UltimusUserID; respuesta = CorreoAPI.EnviarCorreoAutomatico(Correo); } catch (Exception ex) { logs.Error(ex); respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); return respuesta; } return respuesta; } public BaseJson EnviarNotificacionCliente(FormalizacionJSON model) { BaseJson respuesta = new BaseJson(); CorreosAutomaticosPendientes Correo = new CorreosAutomaticosPendientes(); EnvioCorreoAPIController CorreoAPI = new EnvioCorreoAPIController(); Etapas etapa = new Etapas(); EtapasDAL EtapaDAL = new EtapasDAL(); try { etapa = EtapaDAL.ObtenerEtapa(model.UltimusStep); Correo.IdCorreo = 0; Correo.IdSolicitud = model.DatosGeneralesFormalizacion.IdSolicitud; Correo.IdEtapa = etapa.IdEtapa; Correo.IdProceso = model.DatosGeneralesFormalizacion.IdProceso; Correo.Incident = model.DatosGeneralesFormalizacion.Incident; Correo.NombreFiltroCorreo = "AcreditacionDesembolsoCliente"; Correo.UserID = model.UltimusUserID; respuesta = CorreoAPI.EnviarCorreoAutomatico(Correo); } catch (Exception ex) { logs.Error(ex); respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString(); return respuesta; } return respuesta; } #endregion } }