Exemplo n.º 1
0
        public ActionResult Editar(TablaViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (refugioEntities db = new refugioEntities())
                    {
                        var gato = db.Gatos.Find(model.ID);
                        gato.NOMBRE   = model.NOMBRE;
                        gato.RAZA     = model.RAZA;
                        gato.EDAD     = model.EDAD;
                        gato.CASTRADO = model.CASTRADO;

                        db.Entry(gato).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    return(Redirect("~/Tabla/Index"));
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 2
0
        public ActionResult SessionEnter(string pass, string passRepeat)
        {
            string ePass       = Encrypt.GetSHA256(pass);
            string ePassRepeat = Encrypt.GetSHA256(passRepeat);
            string usuario     = "admin";

            string passVerify = null;

            try
            {
                if (ePass == ePassRepeat)
                {
                    passVerify = ePass;
                }
                else
                {
                    return(Content("Contraseña invalida"));
                }

                if (passVerify == "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918")
                {
                    return(Content("La contraseña que quiere poner, no se puede"));
                }

                using (refugioEntities db = new refugioEntities())

                {
                    if (ModelState.IsValid)
                    {
                        {
                            var oUser = db.Adm.Find(1);
                            oUser.PASS            = passVerify;
                            db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                        var lst = from d in db.Adm
                                  where d.USUARIO == usuario && d.PASS == ePass
                                  select d;
                        if (lst.Count() > 0)
                        {
                            Session["User"] = lst.First();
                            return(Content("Logueado correctamente!"));
                        }
                    }
                    return(Redirect("~/Tabla/Index"));
                }
            }
            catch (Exception ex)
            {
                return(Content("Ocurrio un error" + ex.Message));
            }
        }
Exemplo n.º 3
0
        public ActionResult RecoverPass(string email)
        {
            ListSession model        = new ListSession();
            string      pass         = "******";
            string      emailOrigen  = "*****@*****.**";
            string      emailDestino = email;
            string      password     = "******";

            try
            {
                if (ModelState.IsValid)
                {
                    using (refugioEntities db = new refugioEntities())
                    {
                        var user = db.Adm.Where(d => d.EMAIL == email).FirstOrDefault();

                        if (user != null)
                        {
                            user.PASS            = pass;
                            db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            MailMessage oEmail = new MailMessage(emailOrigen, emailDestino, "Hola", "Su nueva contraseña es admin");
                            oEmail.IsBodyHtml = true;
                            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
                            smtpClient.EnableSsl             = true;
                            smtpClient.UseDefaultCredentials = false;
                            //smtpClient.Host = "smtp.gmail.com";
                            smtpClient.Port        = 587;
                            smtpClient.Credentials = new System.Net.NetworkCredential(emailOrigen, password);

                            smtpClient.Send(oEmail);
                            smtpClient.Dispose();

                            return(Content("Contraseña enviada"));
                        }
                        else
                        {
                            return(Content("El correo no es valido"));
                        }
                    }
                }
                return(Content("Ocurrio un errror"));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }