コード例 #1
0
        public JsonResult EnviarCambioEstado(int Id, int estado, string csctvo_slctd, string crreo_jfe_slctnte, DateTime fcha_inco_vccns, DateTime fcha_fn_vcc, string nmbre_cmplto, int fk_slctd_encbzdo, string crreo_slctnte, string crro_antdr)
        {
            ConsumoAPIAprobacion  cons = new ConsumoAPIAprobacion();
            ResultadoCambioEstado oMensajeRespuesta = new ResultadoCambioEstado();

            oMensajeRespuesta = cons.CambiarEstadoSolicitud(Id, estado);

            string oIdDecodificado     = StringCipher.Decrypt(csctvo_slctd);
            string oCorreoDecodificado = StringCipher.Decrypt(crreo_jfe_slctnte);

            MensajeRespuesta DataGrid = new MensajeRespuesta();

            DataGrid = cons.ConsultarAprobacionRechazo(int.Parse(oIdDecodificado), oCorreoDecodificado);
            if (oMensajeRespuesta.Codigo == 1 && estado == 3)
            {
                ConsumoAPIFlow consFlow = new ConsumoAPIFlow();
                FlowModels     item     = new FlowModels();
                item.cnsctvo_slctd     = fk_slctd_encbzdo;
                item.CorreoJefe        = crreo_jfe_slctnte;
                item.correoSolicitante = crreo_slctnte;
                item.correoAnotador    = crro_antdr;
                item.fecha_inicio      = fcha_inco_vccns.ToString();
                item.fecha_fin         = fcha_fn_vcc.ToString();
                item.opt = 2;
                item.nombreSolicitante = nmbre_cmplto;
                MensajeRespuesta mensajeCorreo = new MensajeRespuesta();
                mensajeCorreo = consFlow.EnviarNotificacionFlow(item);
            }



            DataGrid.Codigo  = oMensajeRespuesta.Codigo.ToString();
            DataGrid.Mensaje = oMensajeRespuesta.Respuesta.ToString();

            return(Json(DataGrid, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public JsonResult GuardarSolicitud(string NroIdentificacion, string NombresEmpleado, string ApellidosEmpleado,
                                           string oRespuestaSAP, string oRespuestaMotor, string NumeroDias,
                                           string SabadoHabil, string FechaInicio, string FechaFin,
                                           string NroMinDiasCorreoCompensacion, string CorreoCompensacion)
        {
            MensajeRespuesta           oMensajeRespuesta           = new MensajeRespuesta();
            ConsumoAPIGuardarSolicitud oConsumoAPIGuardarSolicitud = new ConsumoAPIGuardarSolicitud();
            RespuestaSAPModels         oRespuestaSAPModels         = new RespuestaSAPModels();
            RespuestaMotorModels       oRespuestaMotorModels       = new RespuestaMotorModels();
            List <SolicitudDetalle>    oLstSolicitudDetalle        = new List <SolicitudDetalle>();
            Solicitudes    oSolicitudes    = new Solicitudes();
            ConsumoAPIFlow oConsumoApiFlow = new ConsumoAPIFlow();
            RespuestaGuardarSolicitudModels oRespuestaGuardarSolicitudModels = new RespuestaGuardarSolicitudModels();
            UtilitiesGenerales oUtilitiesGenerales = new UtilitiesGenerales();


            try
            {
                string NombreUser = System.Web.HttpContext.Current.User.Identity.Name;
                int    backSlash  = NombreUser.IndexOf("\\");
                string UserName   = backSlash > 0 ? NombreUser.Substring(backSlash + 1) : NombreUser;


                oRespuestaSAPModels   = JsonConvert.DeserializeObject <RespuestaSAPModels>(oRespuestaSAP);
                oRespuestaMotorModels = JsonConvert.DeserializeObject <RespuestaMotorModels>(oRespuestaMotor);

                oLstSolicitudDetalle.Add(new SolicitudDetalle
                {
                    nmbrs_slctnte        = HttpUtility.HtmlDecode(NombresEmpleado),
                    apllds_slctnte       = HttpUtility.HtmlDecode(ApellidosEmpleado),
                    fcha_inco_vccns      = Convert.ToDateTime(FechaInicio),
                    fcha_fn_vcc          = Convert.ToDateTime(FechaFin),
                    nmro_ds              = int.Parse(NumeroDias),
                    sbdo_hbl             = oRespuestaSAPModels.Details[0].SabadoHabil == "NO" ? false : true,
                    fcha_hra_aprvc       = DateTime.Now,
                    fcha_hra_rgstro_nvdd = DateTime.Now,
                    crreo_slctnte        = !string.IsNullOrEmpty(oRespuestaSAPModels.Details[0].CorreoCorp) ? oRespuestaSAPModels.Details[0].CorreoCorp : oRespuestaSAPModels.Details[0].CorreoPersonal,
                    crreo_jfe_slctnte    = !string.IsNullOrEmpty(oRespuestaSAPModels.Details[0].CorreoCorpJefe) ? oRespuestaSAPModels.Details[0].CorreoCorpJefe : oRespuestaSAPModels.Details[0].CorreoPersonalJefe,
                    codEmpldo            = oRespuestaSAPModels.Details[0].NroPersonal,
                    idEstdoSlctd         = 1,
                    scdd                         = oRespuestaSAPModels.Details[0].Sociedad,
                    idntfccn_slctnte             = NroIdentificacion,
                    NroMinDiasCorreoCompensacion = int.Parse(NroMinDiasCorreoCompensacion),
                    CorreoCompensacion           = CorreoCompensacion
                });

                oSolicitudes.fcha_hra_slctd = DateTime.Now;
                oSolicitudes.nmbrs_slctnte  = HttpUtility.HtmlDecode(NombresEmpleado);
                oSolicitudes.apllds_slctnte = HttpUtility.HtmlDecode(ApellidosEmpleado);
                oSolicitudes.nmro_idntfccn  = NroIdentificacion;
                oSolicitudes.cdgo_escenario = oRespuestaMotorModels.Escenario[0].Cdgo;
                oSolicitudes.detalle        = oLstSolicitudDetalle;
                oSolicitudes.crro_antdr     = "";
                oSolicitudes.ip             = oUtilitiesGenerales.ObtenerIp();
                oSolicitudes.nmbre_usrio    = UserName;
                oSolicitudes.nmbre_eqpo     = oUtilitiesGenerales.ObtenerNombreMaquina();

                oMensajeRespuesta = oConsumoAPIGuardarSolicitud.AlmacenarSolicitud(oSolicitudes);

                if (oMensajeRespuesta.Codigo == "1")
                {
                    string oRespuestaGuardarSolicitud = JsonConvert.SerializeObject(oMensajeRespuesta.Resultado.Data, Formatting.Indented);

                    oRespuestaGuardarSolicitudModels = JsonConvert.DeserializeObject <RespuestaGuardarSolicitudModels>(oRespuestaGuardarSolicitud);



                    string URIAprobacionyRechazo = Request.Url.Scheme +                         //Https
                                                   "://" + Request.Url.Authority +              //WWW.
                                                   Request.ApplicationPath.TrimEnd('/') + "/" + //Base del sitio
                                                   URIAprobacion +                              // AprobacionYRechazo/Index
                                                   IdSolicitud + HttpUtility.UrlEncode(StringCipher.Encrypt(oRespuestaGuardarSolicitudModels.Resultado.ToString())) + "&" +
                                                   CorreoJefe + HttpUtility.UrlEncode(StringCipher.Encrypt(oLstSolicitudDetalle[0].crreo_jfe_slctnte));


                    FlowModels oFlow = new FlowModels
                    {
                        correoSolicitante = oLstSolicitudDetalle[0].crreo_slctnte,
                        nombreSolicitante = HttpUtility.HtmlDecode(oLstSolicitudDetalle[0].nmbrs_slctnte) + " " + HttpUtility.HtmlDecode(oLstSolicitudDetalle[0].apllds_slctnte),
                        fecha_fin         = oLstSolicitudDetalle[0].fcha_fn_vcc.ToShortDateString(),
                        fecha_inicio      = oLstSolicitudDetalle[0].fcha_inco_vccns.ToShortDateString(),
                        CorreoJefe        = oLstSolicitudDetalle[0].crreo_jfe_slctnte,
                        url = "<a href=" + URIAprobacionyRechazo + ">Haga clic aqui </a>",
                        opt = 1
                    };

                    oConsumoApiFlow.EnviarNotificacionFlow(oFlow);

                    if (oLstSolicitudDetalle[0].nmro_ds <= int.Parse(NroMinDiasCorreoCompensacion))
                    {
                        FlowModels oFlowMesaCompensacion = new FlowModels
                        {
                            CorreoCompensacion = CorreoCompensacion,
                            nombreSolicitante  = HttpUtility.HtmlDecode(oLstSolicitudDetalle[0].nmbrs_slctnte) + " " + HttpUtility.HtmlDecode(oLstSolicitudDetalle[0].apllds_slctnte),
                            fecha_inicio       = oLstSolicitudDetalle[0].fcha_inco_vccns.ToShortDateString(),
                            fecha_fin          = oLstSolicitudDetalle[0].fcha_fn_vcc.ToShortDateString(),
                            opt = 5
                        };

                        oConsumoApiFlow.EnviarNotificacionFlow(oFlowMesaCompensacion);
                    }
                }


                return(Json(oMensajeRespuesta, JsonRequestBehavior.AllowGet));
            }
            catch (Exception Ex)
            {
                Logger.Error("Ocurrió un error almacenando la solicitud de vacaciones. Nro Documento Encabezado: " +
                             oSolicitudes.nmro_idntfccn +
                             ". Exception: " + Ex);

                oMensajeRespuesta.Codigo    = "-3";
                oMensajeRespuesta.Mensaje   = "Ocurrió un error almacenando la solicitud de vacaciones. Contacte al administrador del sistema";
                oMensajeRespuesta.Resultado = Json(JsonConvert.SerializeObject(oMensajeRespuesta, Formatting.Indented), JsonRequestBehavior.AllowGet);

                return(Json(oMensajeRespuesta, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        public JsonResult EnviarNotificacionFlow(string oDataActual, string oIdSolicitud, string oRespuestaSAP)
        {
            List <SolicitudDetalle> oLstSolicitudDetalle = new List <SolicitudDetalle>();
            List <string>           oLstCorreos          = new List <string>();
            MensajeRespuesta        oMensajeRespuesta    = new MensajeRespuesta();
            RespuestaSAPModels      oRespuestaSAPModels  = new RespuestaSAPModels();
            ConsumoAPIFlow          oConsumoApiFlow      = new ConsumoAPIFlow();
            FlowModels oFlow             = new FlowModels();
            FlowModels oFlowCompensacion = new FlowModels();
            string     oTableAnotador    = string.Empty;
            string     oTableJefes       = string.Empty;
            string     oCorreoAnotador   = string.Empty;

            try
            {
                string URIAprobacionyRechazo = Request.Url.Scheme +                         //Https
                                               "://" + Request.Url.Authority +              //WWW.
                                               Request.ApplicationPath.TrimEnd('/') + "/" + //Base del sitio
                                               URIAprobacion +                              // AprobacionYRechazo/Index
                                               IdSolicitud + HttpUtility.UrlEncode(StringCipher.Encrypt(oIdSolicitud)) + "&" +
                                               CorreoJefe;



                oRespuestaSAPModels = JsonConvert.DeserializeObject <RespuestaSAPModels>(oRespuestaSAP);


                oCorreoAnotador = !string.IsNullOrEmpty(oRespuestaSAPModels.Details[0].CorreoCorp) ? oRespuestaSAPModels.Details[0].CorreoCorp : oRespuestaSAPModels.Details[0].CorreoPersonal;

                //Se declara inicio de la tabla para el correo de los anotadores
                oTableAnotador = "<Table cellpadding=0 cellspacing=0 border=1>";


                oLstSolicitudDetalle = GenerarObjetoSolicitudDetalle(oDataActual);

                if (oLstSolicitudDetalle != null && oLstSolicitudDetalle.Count > 0)
                {
                    //Se crean los encabezados para la tabla del anotador
                    oTableAnotador += "<tr>" +
                                      "<th> Nro. de identificación </th>" +
                                      "<th> Nombres y apellidos </th>" +
                                      "<th> Inicio de vacaciones </th>" +
                                      "<th> Fin de vacaciones </th>" +
                                      "<th> Nro. de días a disfrutar </th> " +
                                      "</tr>";

                    foreach (SolicitudDetalle oSolicitudDetalle in oLstSolicitudDetalle)
                    {
                        if (oLstCorreos == null && oLstCorreos.Count == 0)
                        {
                            oLstCorreos.Add(oSolicitudDetalle.crreo_jfe_slctnte);
                        }
                        else
                        {
                            int Count = oLstCorreos.Count(element => element == oSolicitudDetalle.crreo_jfe_slctnte);
                            if (Count == 0)
                            {
                                oLstCorreos.Add(oSolicitudDetalle.crreo_jfe_slctnte);
                            }
                        }

                        //Se adiciona cada uno de los empleados a la tabla del anotador
                        oTableAnotador += "<tr>" +
                                          "<td>" + oSolicitudDetalle.idntfccn_slctnte + "</td>" +
                                          "<td>" + oSolicitudDetalle.nmbrs_slctnte + oSolicitudDetalle.apllds_slctnte + "</td>" +
                                          "<td>" + oSolicitudDetalle.fcha_inco_vccns.ToShortDateString() + "</td>" +
                                          "<td>" + oSolicitudDetalle.fcha_fn_vcc.ToShortDateString() + "</td>" +
                                          "<td>" + oSolicitudDetalle.nmro_ds + "</td>" +
                                          "</tr>";
                    }
                }

                //Se cierra la tabla del anotador
                oTableAnotador += "</Table>";

                oFlow = new FlowModels
                {
                    correoAnotador = oCorreoAnotador,
                    lista          = oTableAnotador,
                    opt            = 6
                };

                oTableAnotador = string.Empty;

                oMensajeRespuesta = new MensajeRespuesta();
                //Aqui se debe enviar notificacion individual
                oMensajeRespuesta = oConsumoApiFlow.EnviarNotificacionFlow(oFlow);

                if (oMensajeRespuesta.Codigo != "1")
                {
                    Logger.Error("Ocurrió un error enviando las notificaciones por correo electrónico para el anotador con correo: " + oCorreoAnotador +
                                 ". Id de la solicitud: " + IdSolicitud);
                }


                foreach (var oCorreo in oLstCorreos)
                {
                    oTableJefes  = "<Table cellpadding=0 cellspacing=0 border=1>";
                    oTableJefes += "<tr>" +
                                   "<th> Nro. de identificación </th>" +
                                   "<th> Nombres y apellidos </th>" +
                                   "<th> Inicio de vacaciones </th>" +
                                   "<th> Fin de vacaciones </th>" +
                                   "<th> Nro. de días a disfrutar </th> " +
                                   "</tr>";

                    foreach (var oDetalle in oLstSolicitudDetalle)
                    {
                        if (oDetalle.crreo_jfe_slctnte == oCorreo)
                        {
                            oTableJefes += "<tr>" +
                                           "<td>" + oDetalle.idntfccn_slctnte + "</td>" +
                                           "<td>" + oDetalle.nmbrs_slctnte + oDetalle.apllds_slctnte + "</td>" +
                                           "<td>" + oDetalle.fcha_inco_vccns.ToShortDateString() + "</td>" +
                                           "<td>" + oDetalle.fcha_fn_vcc.ToShortDateString() + "</td>" +
                                           "<td>" + oDetalle.nmro_ds + "</td>" +
                                           "</tr>";


                            oFlow.correoSolicitante = oDetalle.crreo_slctnte;
                            oFlow.nombreSolicitante = HttpUtility.HtmlDecode(oDetalle.nmbrs_slctnte) + " " + HttpUtility.HtmlDecode(oDetalle.apllds_slctnte);
                            oFlow.fecha_inicio      = oDetalle.fcha_inco_vccns.ToShortDateString();
                            oFlow.fecha_fin         = oDetalle.fcha_fn_vcc.ToShortDateString();
                            oFlow.opt = 4;

                            oMensajeRespuesta = new MensajeRespuesta();
                            //Aqui se debe enviar notificacion individual
                            oMensajeRespuesta = oConsumoApiFlow.EnviarNotificacionFlow(oFlow);

                            if (oMensajeRespuesta.Codigo != "1")
                            {
                                Logger.Error("Ocurrió un error enviando las notificaciones por correo electrónico para el empleado con código SAP: " +
                                             oDetalle.codEmpldo + ". Nombre Completo: " + oDetalle.nmbrs_slctnte + oDetalle.apllds_slctnte +
                                             ". Id solcicitud: " + IdSolicitud);
                                oMensajeRespuesta = new MensajeRespuesta();
                            }


                            if (oDetalle.nmro_ds <= oDetalle.NroMinDiasCorreoCompensacion)
                            {
                                oFlowCompensacion = new FlowModels();
                                oFlowCompensacion.CorreoCompensacion = oDetalle.CorreoCompensacion;
                                oFlowCompensacion.nombreSolicitante  = HttpUtility.HtmlDecode(oDetalle.nmbrs_slctnte) + " " + HttpUtility.HtmlDecode(oDetalle.apllds_slctnte);
                                oFlowCompensacion.fecha_inicio       = oDetalle.fcha_inco_vccns.ToShortDateString();
                                oFlowCompensacion.fecha_fin          = oDetalle.fcha_fn_vcc.ToShortDateString();
                                oFlowCompensacion.opt = 5;

                                oMensajeRespuesta = new MensajeRespuesta();
                                //Aqui se debe enviar notificacion individual
                                oMensajeRespuesta = oConsumoApiFlow.EnviarNotificacionFlow(oFlowCompensacion);

                                if (oMensajeRespuesta.Codigo != "1")
                                {
                                    Logger.Error("Ocurrió un error enviando las notificaciones por correo electrónico para el empleado con código SAP: " +
                                                 oDetalle.codEmpldo + ". Nombre Completo: " + oDetalle.nmbrs_slctnte + oDetalle.apllds_slctnte +
                                                 ". Id solcicitud: " + IdSolicitud);
                                    oMensajeRespuesta = new MensajeRespuesta();
                                }
                            }
                        }
                    }

                    oTableJefes += "</Table>";

                    oFlow = new FlowModels
                    {
                        CorreoJefe = oCorreo,
                        lista      = oTableJefes,
                        url        = "<a href=" + URIAprobacionyRechazo + HttpUtility.UrlEncode(StringCipher.Encrypt(oCorreo)) + ">Haga clic aqui </a>",
                        opt        = 3
                    };

                    oTableJefes = string.Empty;

                    oMensajeRespuesta = new MensajeRespuesta();
                    //Aqui se debe enviar notificacion individual
                    oMensajeRespuesta = oConsumoApiFlow.EnviarNotificacionFlow(oFlow);

                    if (oMensajeRespuesta.Codigo != "1")
                    {
                        Logger.Error("Ocurrió un error enviando las notificaciones por correo electrónico para el jefe con correo: " + oCorreo +
                                     ". Id de la solicitud: " + IdSolicitud);
                    }
                }

                oMensajeRespuesta           = new MensajeRespuesta();
                oMensajeRespuesta.Codigo    = "1";
                oMensajeRespuesta.Mensaje   = "Se genero la lista de correos satisfactoriamente";
                oMensajeRespuesta.Resultado = Json(oLstCorreos, JsonRequestBehavior.AllowGet);

                return(Json(oMensajeRespuesta, JsonRequestBehavior.AllowGet));
            }
            catch (Exception Ex)
            {
                Logger.Error("Ocurrió un error enviando las notificaciones por correo electrónico." +
                             ". Exception: " + Ex);

                oMensajeRespuesta.Codigo  = "-1";
                oMensajeRespuesta.Mensaje = "Ocurrió un error enviando las notificaciones por correo electrónico. Contacte al administrador del sistema";
                return(Json(oMensajeRespuesta, JsonRequestBehavior.AllowGet));
            }
        }