예제 #1
0
        public bool SendMail(string To_Mail, Evento evento)
        {
            try
            {
                MailMessage smail = new MailMessage();
                smail.IsBodyHtml   = true;
                smail.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
                smail.From         = new MailAddress("*****@*****.**", "*****@*****.**");

                string[] emails = To_Mail.Split(',');
                foreach (string email in emails)
                {
                    if (email != "")
                    {
                        smail.To.Add(email);
                    }
                }

                smail.Subject = "[PMMX Notification] Info: " + evento.Descripcion;
                smail.Body    = string.Format("<html><head><meta charset='UTF-8'></head><body>  ");
                smail.Body    = smail.Body + string.Format("<div align='center' style='font-weight:bold; text-align: center; width:50%; margin: 0 auto; display: table; background: #D6EAF8;' >");
                smail.Body    = smail.Body + string.Format(" <h1 style ='text - transform: uppercase; background: #21618C; color: #FFFFFF;'> New Event </h1></div>");
                smail.Body    = smail.Body + string.Format("<span style = 'font - family:Arial; font - size:10pt'> ");
                smail.Body    = smail.Body + string.Format("   A new event has been asigned to you <h3>" + evento.Descripcion + "</h3> to " + evento.FechaInicio);
                smail.Body    = smail.Body + string.Format(" <br /><br /></span> ");
                smail.Body    = smail.Body + string.Format("<h3 style ='text - transform: uppercase; background: #21618C; color: #FFFFFF;'>"
                                                           + "<a style='color: #FFFFFF;'' href='https://serverpmi.tr3sco.net/'>For more information click here</a>"
                                                           + "<br /></h3> ");
                smail.Body = smail.Body + string.Format(" </body></html> ");

                SmtpClient smtp = new SmtpClient();
                smtp.Host                  = "smtp.gmail.com";
                smtp.Port                  = 587;
                smtp.EnableSsl             = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "82000100");
                smtp.Send(smail);

                NotificationService notify          = new NotificationService();
                UsuarioServicio     usuarioServicio = new UsuarioServicio();

                List <DispositivoView> dispositivos = usuarioServicio.GetDispositivoByEvento(evento.Id);
                List <string>          llaves       = dispositivos.Select(x => x.Llave).ToList();

                foreach (string notificacion in llaves)
                {
                    notify.SendPushNotification(notificacion, "Evento: " + evento.Descripcion + ". ", " A new event has been asigned to you " + evento.Descripcion + " to " + evento.FechaInicio);
                }
            }
            catch (SmtpException ex)
            {
                Console.WriteLine(ex.StatusCode);
                Console.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
예제 #2
0
        public bool SendNotification(Evento evento, String mensaje)
        {
            NotificationService notify          = new NotificationService();
            UsuarioServicio     usuarioServicio = new UsuarioServicio();

            List <DispositivoView> dispositivos = usuarioServicio.GetDispositivoByEvento(evento.Id);
            List <string>          llaves       = dispositivos.Select(x => x.Llave).ToList();

            foreach (string notificacion in llaves)
            {
                notify.SendPushNotification(notificacion, mensaje + evento.Descripcion + ". ", "");
            }

            string       senders      = usuarioServicio.GetEmailByEvento(evento.Id);
            EmailService emailService = new EmailService();

            emailService.SendMail(senders, evento);

            return(true);
        }
예제 #3
0
        public IHttpActionResult PostEvento(Evento evento)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (evento.Nota == null)
            {
                evento.Nota = " ";
            }

            evento.FechaInicio = DateTime.Now;
            evento.FechaFin    = DateTime.Now;
            evento.Activo      = true;

            db.Evento.Add(evento);
            db.SaveChanges();

            try
            {
                NotificationService notify          = new NotificationService();
                UsuarioServicio     usuarioServicio = new UsuarioServicio();

                List <DispositivoView> dispositivos = usuarioServicio.GetDispositivoByEvento(evento.Id);
                List <string>          llaves       = dispositivos.Select(x => x.Llave).ToList();

                foreach (string notificacion in llaves)
                {
                    notify.SendPushNotification(notificacion, "Se le ha asignado un nuevo evento: " + evento.Descripcion + ". ", "");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            return(Ok(evento));
        }
예제 #4
0
        public bool SendMail(string To_Mail, Ventana ventana)
        {
            try
            {
                MailMessage smail = new MailMessage();
                smail.IsBodyHtml   = true;
                smail.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
                smail.From         = new MailAddress("*****@*****.**", "*****@*****.**");

                string[] emails = To_Mail.Split(',');
                foreach (string email in emails)
                {
                    if (email != "")
                    {
                        smail.To.Add(email);
                    }
                }

                var estatus = ventana.StatusVentana.OrderByDescending(s => s.Fecha).Select(s => s.Status).FirstOrDefault();

                smail.Subject = "[PMMX Notification] Ventana: " + ventana.PO + " " + ventana.Proveedor.NombreCorto + " " + ventana.NombreCarrier;
                smail.Body    = string.Format("<html><head><meta charset='UTF-8'></head>");
                smail.Body    = smail.Body + string.Format("<body> <div style='width:100%'>"
                                                           + "<div align='center' style='font-weight:bold; text-align: center; width:50%; margin: 0 auto; display: table; background: #D6EAF8;' >");
                smail.Body = smail.Body + string.Format(" <h1 style ='text - transform: uppercase; background: #21618C; color: #FFFFFF;'> Ventana " + ventana.PO + " " + ventana.Proveedor.NombreCorto + " " + ventana.NombreCarrier + " </h1>");
                smail.Body = smail.Body + string.Format("Has been change to status to <span style='color: #5caad2;'>" + estatus.Nombre);

                if (ventana.BitacoraVentana.Where(b => (b.IdVentana == ventana.Id) && (b.Estatus.Id == estatus.Id)).OrderByDescending(v => v.Fecha).Select(v => v.IdRechazo).Count() > 0)
                {
                    smail.Body = smail.Body + string.Format(" Rejected by"
                                                            + "</br><span style='color: #21618C;'>"
                                                            + ventana.BitacoraVentana.OrderByDescending(s => s.Fecha).Select(s => s.Rechazo.Nombre).FirstOrDefault()
                                                            + "</span>");
                }

                smail.Body = smail.Body + string.Format(" <br /><br /><br /><br /> ");
                smail.Body = smail.Body + string.Format("<h3 style ='text - transform: uppercase; background: #21618C; color: #FFFFFF;'><a style='color: #FFFFFF;'' href='https://serverpmi.tr3sco.net/'>For more information click here</a><br /></h3> ");
                smail.Body = smail.Body + string.Format(" </div>"
                                                        + "</div>"
                                                        + "</body>"
                                                        + "</html> ");

                SmtpClient smtp = new SmtpClient();
                smtp.Host                  = "smtp.gmail.com";
                smtp.Port                  = 587;
                smtp.EnableSsl             = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "82000100");
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.Timeout               = 100000;
                smtp.Send(smail);

                NotificationService notify          = new NotificationService();
                UsuarioServicio     usuarioServicio = new UsuarioServicio();

                List <DispositivoView> dispositivos = usuarioServicio.GetDispositivoByEvento(ventana.IdEvento);
                List <string>          llaves       = dispositivos.Select(x => x.Llave).ToList();

                foreach (string notificacion in llaves)
                {
                    notify.SendPushNotification(notificacion, "Ventana: " + ventana.Evento.Descripcion + ". ", "La ventana " + ventana.Evento.Descripcion + " ha cambiado de estatus a " + estatus.Nombre);
                }
            }
            catch (SmtpException ex)
            {
                Console.WriteLine(ex.StatusCode);
                Console.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
예제 #5
0
        public IHttpActionResult PostStatusVentana(StatusVentana statusVentana)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var IdSubCategoria = db.Ventana.Where(x => x.Id == statusVentana.IdVentana).Select(x => x.IdSubCategoria).FirstOrDefault();
                var IdActualStatus = db.StatusVentana.OrderByDescending(x => x.Fecha).Where(x => x.IdVentana == statusVentana.IdVentana).Select(x => x.IdStatus).FirstOrDefault();

                WorkFlowServicio workflowServicio          = new WorkFlowServicio();
                IRespuestaServicio <WorkFlowView> workFlow = workflowServicio.nextEstatus(IdSubCategoria, IdActualStatus, false);

                statusVentana.IdStatus = workFlow.Respuesta.EstatusSiguiente.Id;
                statusVentana.Fecha    = DateTime.Now;
                db.StatusVentana.Add(statusVentana);
                db.SaveChanges();

                var ventana = db.Ventana
                              .Include(v => v.StatusVentana)
                              .Include(v => v.StatusVentana.Select(s => s.Status))
                              .Include(v => v.BitacoraVentana)
                              .Include(v => v.BitacoraVentana.Select(b => b.Estatus))
                              .Include(v => v.BitacoraVentana.Select(b => b.Rechazo))
                              .Include(v => v.Evento)
                              .Where(x => x.Id == statusVentana.IdVentana)
                              .FirstOrDefault();

                UsuarioServicio     usuarioServicio = new UsuarioServicio();
                NotificationService notify          = new NotificationService();

                string senders = usuarioServicio.GetEmailByStatus(ventana);

                if (senders != "")
                {
                    EmailService emailService = new EmailService();
                    emailService.SendMail(senders, ventana);
                }

                List <DispositivoView> dispositivos = usuarioServicio.GetDispositivoByEvento(statusVentana.Ventana.IdEvento);
                List <string>          llaves       = dispositivos.Select(x => x.Llave).ToList();
                var estatus = ventana.StatusVentana.OrderByDescending(s => s.Fecha).Select(s => s.Status).FirstOrDefault();

                if (llaves.Count > 0)
                {
                    foreach (string notificacion in llaves)
                    {
                        notify.SendPushNotification(notificacion, " Cambio de estatus Ventana: " + ventana.Evento.Descripcion + ". ", " Cambio de estatus a " + estatus.Nombre);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            StatusVentana statusVentanaAdded = db.StatusVentana.Find(statusVentana.Id);

            return(Ok(statusVentanaAdded));
        }