Пример #1
0
        public ActionResult Mensajes(Models.Comunicaciones comunicaciones)
        {
            ViewBag.Rol = Session["Rol"].ToString();

            try
            {
                DATA.Telefonos telefono = new DATA.Telefonos();
                telefono = tel.ListarTelefonos().Where(x => x.Username == Session["Username"].ToString()).FirstOrDefault();
                var dateNow = DateTime.Now;
                comunicaciones.Fecha         = dateNow;
                comunicaciones.Estado        = 4;
                comunicaciones.Numero_Twilio = telefono.Numero;
                DATA.Contactos contacto = new DATA.Contactos();
                contacto = cont.BuscarContactos(comunicaciones.Id_Contacto);

                TwilioClient.Init(telefono.Account_Id, telefono.Authtoken);
                var message = MessageResource.Create(
                    body: comunicaciones.Mensaje,
                    from: new Twilio.Types.PhoneNumber("+" + telefono.Numero),
                    to: new Twilio.Types.PhoneNumber("+" + contacto.Numero)
                    );

                com.InsertarComunicaciones(Mapper.Map <DATA.Comunicaciones>(comunicaciones));


                return(RedirectToAction("Mensajes", new { Id_Contacto = comunicaciones.Id_Contacto }));
            }
            catch (Exception ex)
            {
                ViewBag.Mensaje = ex.Message;
                return(RedirectToAction("Mensajes"));
            }
        }
Пример #2
0
        public ActionResult Index()
        {
            ViewBag.Rol = Session["Rol"].ToString();
            try
            {
                ViewBag.userId = Session["Username"];
                DATA.Telefonos telefono = new DATA.Telefonos();
                telefono = tel.ListarTelefonos().Where(x => x.Username == Session["Username"].ToString()).FirstOrDefault();
                var personasConComunicacion = com.ListarComunicaciones().Where(x => x.Numero_Twilio == telefono.Numero).Select(x => x.Id_Contacto).Distinct();
                var lista     = cont.ListarContactos().Where(x => x.Username == Session["Username"].ToString()).Where(x => personasConComunicacion.Contains(x.Id_Contacto));
                var contactos = Mapper.Map <List <Models.Contactos> >(lista);

                foreach (Models.Contactos a in contactos)
                {
                    var per = com.ListarComunicaciones().Where(x => x.Numero_Twilio == telefono.Numero).Where(x => x.Id_Contacto == a.Id_Contacto).Where(x => x.Estado == 6).FirstOrDefault();
                    if (per != null)
                    {
                        a.lista_negra = "Si";
                    }
                    else
                    {
                        a.lista_negra = "No";
                    }
                }

                return(View(contactos));
            }
            catch (Exception ex)
            {
                ViewBag.Mensaje = ex.Message;
                return(View());
            }
        }
Пример #3
0
        public JsonResult ListarRecibidos()
        {
            ViewBag.userId = Session["Username"];
            DATA.Telefonos telefono = new DATA.Telefonos();
            telefono = tel.ListarTelefonos().Where(x => x.Username == Session["Username"].ToString()).FirstOrDefault();
            var personasConComunicacion = com.ListarComunicaciones().Where(x => x.Numero_Twilio == telefono.Numero).Where(x => x.Estado == 6).Select(x => x.Id_Contacto).Distinct();
            var lista     = cont.ListarContactos().Where(x => x.Username == Session["Username"].ToString()).Where(x => personasConComunicacion.Contains(x.Id_Contacto));
            var contactos = Mapper.Map <List <Models.Contactos> >(lista);

            foreach (Models.Contactos a in contactos)
            {
                var max = com.ListarComunicaciones().Where(x => x.Numero_Twilio == telefono.Numero).Where(x => x.Id_Contacto == a.Id_Contacto).Select(x => x.Fecha).Max();
                var per = com.ListarComunicaciones().Where(x => x.Numero_Twilio == telefono.Numero).Where(x => x.Id_Contacto == a.Id_Contacto).Where(x => x.Fecha == max).FirstOrDefault();

                a.Detalle     = per.Mensaje;
                a.lista_negra = per.Fecha.ToString();
            }
            return(Json(contactos, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult Index(Models.Difusiones difusion)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool     permitirEnvio = false;
                    DateTime dateSend;
                    var      dateNow = DateTime.Now;
                    difusion.Fecha = dateNow;
                    TimeSpan ts;
                    ts = dateNow - dateNow;

                    string tipoEnvio = Request.Form["tipoEnvio"];
                    difusion.Username = Session["Username"].ToString();

                    //Debug.WriteLine(tipoEnvio);
                    if (difusion.Id_Tipo_Mensaje == 3 && difusion.passwordCorreo == null)
                    {
                        ModelState.AddModelError("errorPassword", "Debe escribir la contraseña de su correo para enviar el mensaje.");
                    }

                    if (tipoEnvio == "inmediato")
                    {
                        ts = dateNow - dateNow;
                        difusion.Fecha_Activacion = dateNow;
                        permitirEnvio             = true;
                    }
                    else
                    {
                        try
                        {
                            string   fechaPro = Request.Form["fechaPro"];
                            string[] datos    = fechaPro.Split('-');
                            string   horaPro  = Request.Form["horaPro"];
                            string[] datos2   = horaPro.Split(':');
                            dateSend = new DateTime(Int32.Parse(datos[0]), Int32.Parse(datos[1]), Int32.Parse(datos[2]), Int32.Parse(datos2[0]), Int32.Parse(datos2[1]), 00);

                            if (dateSend > dateNow)
                            {
                                ts            = dateSend - dateNow;
                                permitirEnvio = true;
                            }
                            else
                            {
                                ModelState.AddModelError("fechaerror", "No puede programar un envio para una fecha ya pasada.");
                            }

                            difusion.Fecha_Activacion = dateSend;
                        } catch (Exception e)
                        {
                            ModelState.AddModelError("fechaerror", "Revise la fecha, ya que algo no parece estar bien.");
                        }
                    }

                    if (permitirEnvio)
                    {
                        var difusionInsertar = Mapper.Map <DATA.Difusiones>(difusion);
                        dif.InsertarDifusiones(difusionInsertar);

                        int             maxId = dif.ListarDifusines().Where(x => x.Username == Session["Username"].ToString()).Max(x => x.Id_Difusion);
                        DATA.Telefonos  telefonoDelUsuario = tel.ListarTelefonos().Where(x => x.Username == Session["Username"].ToString()).First();
                        DATA.Mensajes   mensaje            = mens.ListarMensajes().Where(x => x.Id_Mensaje == difusion.Id_Mensaje).First();
                        DATA.Difusiones difusion2          = dif.BuscarDifusiones(maxId);
                        DATA.Usuarios   correoDelUsuario   = use.ListarUsuarios().Where(x => x.Username == Session["Username"].ToString()).First();

                        Task.Delay(ts).ContinueWith((x) => enviarMensajes(telefonoDelUsuario.Numero, telefonoDelUsuario.Account_Id, telefonoDelUsuario.Authtoken, mensaje.Cuerpo_Mensaje, difusion.Id_Lista, difusion2, correoDelUsuario.Correo, difusion.passwordCorreo));
                    }
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("error", "No se ha podido registrar la difusion.");
                return(RedirectToAction("Index"));
            }


            return(Index());
        }