Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            CORREO cORREO = db.Correos.Find(id);

            db.Correos.Remove(cORREO);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "CorreoId,IdCliente,Correo1")] CORREO cORREO)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cORREO).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cORREO));
 }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "CorreoId,IdCliente,Correo1")] CORREO cORREO)
        {
            if (ModelState.IsValid)
            {
                db.Correos.Add(cORREO);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cORREO));
        }
        public string RecuperarContra(string IIDTIPO, string correo, string telefonoCelular)
        {
            string mensaje = "";

            using (var bd = new BDPasajeEntities())
            {
                int cantidad = 0;
                int iidcliente;
                if (IIDTIPO == "C")
                {
                    //Existe un cliente con esa informacion
                    cantidad = bd.Cliente.Where(p => p.EMAIL == correo && p.TELEFONOCELULAR == telefonoCelular).Count();
                }
                if (cantidad == 0)
                {
                    mensaje = "No existe una persona registrada con esa informacion";
                }
                else
                {
                    iidcliente = bd.Cliente.Where(p => p.EMAIL == correo && p.TELEFONOCELULAR == telefonoCelular).First().IIDCLIENTE;
                    //Verificar si existe el usuario
                    int nveces = bd.Usuario.Where(p => p.IID == iidcliente && p.TIPOUSUARIO == "C").Count();
                    if (nveces == 0)
                    {
                        mensaje = "No tiene usuario";
                    }
                    else
                    {
                        //Ontener su Id
                        Usuario ousuario = bd.Usuario.Where(p => p.IID == iidcliente && p.TIPOUSUARIO == "C").First();
                        //Modificar su clave
                        Random ra          = new Random();
                        int    n1          = ra.Next(0, 9);
                        int    n2          = ra.Next(0, 9);
                        int    n3          = ra.Next(0, 9);
                        int    n4          = ra.Next(0, 9);
                        string nuevaContra = n1.ToString() + n2 + n3 + n4;
                        //Cifrar clave

                        SHA256Managed sha                 = new SHA256Managed();
                        byte[]        byteContra          = Encoding.Default.GetBytes(nuevaContra);
                        byte[]        byteContraCifrado   = sha.ComputeHash(byteContra);
                        string        cadenaContraCifrada = BitConverter.ToString(byteContraCifrado).Replace("-", "");

                        ousuario.CONTRA = cadenaContraCifrada;
                        mensaje         = bd.SaveChanges().ToString();
                        CORREO.enviarCorreo(correo, "Recuperar Clave", "Se reseteo su clave , ahora su clave es :" + nuevaContra, "");
                    }
                }
            }
            return(mensaje);
        }
Beispiel #5
0
        // GET: CORREOs/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CORREO cORREO = db.Correos.Find(id);

            if (cORREO == null)
            {
                return(HttpNotFound());
            }
            return(View(cORREO));
        }
        public string Guardar(UsuarioCLS oUsuarioCLS, int titulo)
        {
            //Vacio es error
            string rpta = "";

            try
            {
                if (!ModelState.IsValid)
                {
                    var query = (from state in ModelState.Values
                                 from error in state.Errors
                                 select error.ErrorMessage).ToList();
                    rpta += "<ul class='list-group'>";
                    foreach (var item in query)
                    {
                        rpta += "<li class='list-group-item'>" + item + "</li>";
                    }
                    rpta += "</ul>";
                }
                else
                {
                    using (var bd = new BDPasajeEntities())
                    {
                        int cantidad = 0;
                        using (var transaccion = new TransactionScope())
                        {
                            if (titulo.Equals(-1))
                            {
                                cantidad = bd.Usuario.Where(p => p.NOMBREUSUARIO == oUsuarioCLS.nombreusuario).Count();
                                if (cantidad >= 1)
                                {
                                    rpta = "-1";
                                }
                                else
                                {
                                    Usuario oUsuario = new Usuario();
                                    oUsuario.NOMBREUSUARIO = oUsuarioCLS.nombreusuario;
                                    SHA256Managed sha                 = new SHA256Managed();
                                    byte[]        byteContra          = Encoding.Default.GetBytes(oUsuarioCLS.contra);
                                    byte[]        byteContraCifrado   = sha.ComputeHash(byteContra);
                                    string        cadenaContraCifrada = BitConverter.ToString(byteContraCifrado).Replace("-", "");
                                    oUsuario.CONTRA      = cadenaContraCifrada;
                                    oUsuario.TIPOUSUARIO = oUsuarioCLS.nombrePersonaEnviar.Substring(oUsuarioCLS.nombrePersonaEnviar.Length - 2, 1);
                                    oUsuario.IID         = oUsuarioCLS.iid;
                                    oUsuario.IIDROL      = oUsuarioCLS.iidrol;
                                    oUsuario.bhabilitado = 1;
                                    bd.Usuario.Add(oUsuario);
                                    Cliente oCliente = null;
                                    if (oUsuario.TIPOUSUARIO.Equals("C"))
                                    {
                                        oCliente = bd.Cliente.Where(p => p.IIDCLIENTE.Equals(oUsuarioCLS.iid)).First();
                                        oCliente.bTieneUsuario = 1;
                                    }
                                    else
                                    {
                                        Empleado oEmpleado = bd.Empleado.Where(p => p.IIDEMPLEADO.Equals(oUsuarioCLS.iid)).First();
                                        oEmpleado.bTieneUsuario = 1;
                                    }
                                    rpta = bd.SaveChanges().ToString();
                                    if (rpta == "0")
                                    {
                                        rpta = "";
                                    }


                                    transaccion.Complete();
                                    if (rpta == "2" && oUsuario.TIPOUSUARIO == "C")
                                    {
                                        string nombreCompleto = (string)Session["nombreCompleto"];
                                        //Buscar el nombre del correo del cliente registrado
                                        string ruta = Server.MapPath("~/Archivos/PersonasCorreo.txt");
                                        int    n    = CORREO.enviarCorreo(oCliente.EMAIL, "Bienvenido al sistema",
                                                                          "<h1>BIENVENIDO AL SISTEMA " + oCliente.NOMBRE + " " + oCliente.APPATERNO + " " + oCliente.APMATERNO + ": </h1> Muchas gracias por formar parte de este curso", ruta);
                                    }
                                }
                            }
                            else
                            {
                                cantidad = bd.Usuario.Where(p => p.NOMBREUSUARIO == oUsuarioCLS.nombreusuario &&
                                                            p.IIDUSUARIO != titulo).Count();

                                if (cantidad >= 1)
                                {
                                    rpta = "-1";
                                }
                                else
                                {
                                    //Editar
                                    Usuario ousuario = bd.Usuario.Where(p => p.IIDUSUARIO == titulo).First();
                                    ousuario.IIDROL        = oUsuarioCLS.iidrol;
                                    ousuario.NOMBREUSUARIO = oUsuarioCLS.nombreusuario;
                                    rpta = bd.SaveChanges().ToString();
                                    transaccion.Complete();
                                }
                            }
                        }
                    }
                }
            }catch (Exception ex)
            {
                rpta = "";
            }
            return(rpta);
        }