212 lines
8.2 KiB
C#
212 lines
8.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Ultimus.Interfaces;
|
|
using Ultimus.Interfaces.UltimusIntegration;
|
|
using Ultimus.Interfaces.UltimusRules;
|
|
using Ultimus.Utilitarios;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using ULA.Cathay.CreditoModel.DAL.Credito;
|
|
|
|
|
|
namespace ULA.Cathay.CreditoModel.BL.Credito
|
|
{
|
|
|
|
|
|
|
|
public class ConfiguracionNotificacionReq
|
|
{
|
|
public int IdNotificationType { get; set; }
|
|
public int Incident { get; set; }
|
|
|
|
public string DescripcionEtapa { get; set; }
|
|
public string NombreProceso { get; set; }
|
|
|
|
public List<string> MailTo { get; set; }
|
|
}
|
|
|
|
|
|
public class ConfiguracionNotificacionResp : BaseJson
|
|
{
|
|
public Email EmailToSend { get; set; }
|
|
}
|
|
|
|
|
|
public class NotificacionBL
|
|
{
|
|
|
|
UltimusLogs log = new UltimusLogs("NotificacionBL");
|
|
|
|
public ConfiguracionNotificacionResp ObtenerNotificacion(ConfiguracionNotificacionReq req)
|
|
{
|
|
string sError = string.Empty;
|
|
ConfiguracionNotificacion configNotificacion = null;
|
|
ConfiguracionNotificacionResp resp = new ConfiguracionNotificacionResp();
|
|
|
|
UltimusUser oUUser = new UltimusUser();
|
|
UltimusIncident oUIncident = new UltimusIncident();
|
|
UltimusIntegrationClient oUIClient = new UltimusIntegrationClient();
|
|
|
|
|
|
try
|
|
{
|
|
configNotificacion = new ConfiguracionNotificacionDAL().Obtener(req.DescripcionEtapa, req.NombreProceso, req.IdNotificationType);
|
|
|
|
#region Informacion Tarea
|
|
if (configNotificacion.SendToTaskUser || configNotificacion.SendToSupervisorTaskUser)
|
|
{
|
|
|
|
if (!oUIClient.GetTaskByFilters(null, req.NombreProceso, req.DescripcionEtapa, req.Incident, out oUIncident, out sError))
|
|
{
|
|
throw new Exception("Ha ocurrido un error al intentar obtener la informacion de la etapa." + sError);
|
|
}
|
|
|
|
req.MailTo.Add(oUIncident.UserEmail);
|
|
|
|
|
|
#region Informacion Supervisor
|
|
if (configNotificacion.SendToSupervisorTaskUser)
|
|
{
|
|
if (!oUIClient.GetUserInformation(oUIncident.Supervisor, out oUUser, out sError))
|
|
{
|
|
throw new Exception("Ha ocurrido un error al intentar obtener la informacion del supervisor." + sError);
|
|
}
|
|
|
|
req.MailTo.Add(oUUser.EmailAddress);
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
string _refBody = configNotificacion.Body;
|
|
string _refSubject = configNotificacion.Subject;
|
|
List<string> _redMailTo = req.MailTo;
|
|
|
|
if (!GetMailData(req.DescripcionEtapa, req.NombreProceso, req.Incident, ref _refBody, ref _refSubject, ref _redMailTo, ref sError))
|
|
{
|
|
throw new Exception(sError);
|
|
}
|
|
|
|
|
|
resp.EmailToSend = new Email()
|
|
{
|
|
Body = _refBody,
|
|
IsBodyHtml = true,
|
|
MailTo = _redMailTo,
|
|
Subject = _refSubject,
|
|
};
|
|
|
|
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
resp.DescripcionRespuesta = string.Empty;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
log.Error(ex);
|
|
}
|
|
return resp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setea los valores a los parametros configurados en el Body y en el Subject del correo.
|
|
/// </summary>
|
|
/// <param name="req">Estructura cargada con la configuracion base obtenida de base de datos</param>
|
|
/// <returns></returns>
|
|
private bool GetMailData(string etapa, string proceso, int incidente, ref string body, ref string subject, ref List<string> mailTo, ref string sError)
|
|
{
|
|
bool boReturn = true;
|
|
|
|
try
|
|
{
|
|
sError = string.Empty;
|
|
|
|
#region ObtenerDatos
|
|
var _modelSolicitud = new SolicitudDAL().Obtener(incidente, proceso);
|
|
if (_modelSolicitud != null) return boReturn;
|
|
|
|
|
|
_modelSolicitud.Solicitante = new SolicitanteDAL().Obtener(_modelSolicitud.IdSolicitud);
|
|
if (_modelSolicitud.Solicitante == null) return boReturn;
|
|
|
|
var _modelClientePrincipal = _modelSolicitud.Solicitante.Where(x => x.EsPrincipal == true).FirstOrDefault();
|
|
if (_modelClientePrincipal == null) return boReturn;
|
|
|
|
_modelClientePrincipal.Cliente.EmailCliente = new EmailClienteDAL().Obtener(_modelClientePrincipal.IdCliente);
|
|
#endregion
|
|
|
|
#region ConfiguracionPorEtapa
|
|
|
|
switch (etapa)
|
|
{
|
|
#region RE_Reco_Dar_Segui
|
|
case "RE_Reco_Dar_Segui":
|
|
|
|
#region FiltrarData
|
|
string NombreCliente = string.Empty;
|
|
switch (_modelClientePrincipal.Cliente.IdTipoCliente)
|
|
{
|
|
case 1:
|
|
string _PrimerNombreDeudor = _modelClientePrincipal.Cliente.PrimerNombre == null ? "" : _modelClientePrincipal.Cliente.PrimerNombre.Trim() + " ";
|
|
string _SegundoNombreDeudor = _modelClientePrincipal.Cliente.SegundoNombre == null ? "" : _modelClientePrincipal.Cliente.SegundoNombre.Trim() + " ";
|
|
string _PrimerApellidoDeudor = _modelClientePrincipal.Cliente.PrimerApellido == null ? "" : _modelClientePrincipal.Cliente.PrimerApellido.Trim() + " ";
|
|
string _SegundorApellidoDeudor = _modelClientePrincipal.Cliente.SegundoApellido == null ? "" : _modelClientePrincipal.Cliente.SegundoApellido.Trim() + " ";
|
|
|
|
NombreCliente = _PrimerNombreDeudor + _SegundoNombreDeudor + _PrimerApellidoDeudor + _SegundorApellidoDeudor;
|
|
break;
|
|
|
|
case 2:
|
|
NombreCliente = _modelClientePrincipal.Cliente.RazonSocial == null ? null : _modelClientePrincipal.Cliente.RazonSocial.Trim();
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
#region Body
|
|
|
|
|
|
body = body.Replace("@NombreCliente", NombreCliente);
|
|
body = body.Replace("@Identificacion", _modelClientePrincipal.Cliente.NumeroIdentificacion.Trim());
|
|
body = body.Replace("@IdSolicitud", _modelSolicitud.IdSolicitud.ToString());
|
|
body = body.Replace("@Incident", _modelSolicitud.Incident.ToString());
|
|
body = body.Replace("@Process", _modelSolicitud.Proceso.Trim());
|
|
|
|
#endregion
|
|
|
|
#region Subject
|
|
subject = subject.Replace("@NombreCliente", NombreCliente);
|
|
subject = subject.Replace("@Identificacion", _modelClientePrincipal.Cliente.NumeroIdentificacion.Trim());
|
|
|
|
#endregion
|
|
|
|
#region Email
|
|
var _EmailClientePersonal = _modelClientePrincipal.Cliente.EmailCliente.Where(x => x.IdTipoEmail == 1).FirstOrDefault();
|
|
|
|
if (_EmailClientePersonal != null && !string.IsNullOrEmpty(_EmailClientePersonal.Email))
|
|
mailTo.Add(_EmailClientePersonal.Email.Trim());
|
|
#endregion
|
|
|
|
break;
|
|
#endregion
|
|
|
|
default:
|
|
|
|
break;
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
boReturn = false;
|
|
sError = ex.Message;
|
|
}
|
|
|
|
return boReturn;
|
|
}
|
|
}
|
|
}
|
|
|