public ActionResult Article(int id)//id del articulo
        {
            List <ArticleTableViewModel> lst = null;

            using (cursomvcEntities db = new cursomvcEntities())
            {
                lst = (from t in db.articulo
                       where t.id == id
                       select new ArticleTableViewModel
                {
                    Nombre = t.nombre,
                    Imagen = t.nombreImg,
                    IdUsu = t.idUsuario,
                    Descripcion = t.descripcion
                }).ToList();

                var u = (from a in db.articulo
                         join b in db.user
                         on a.idUsuario equals b.Id
                         select b.nombre);

                ViewBag.AutorArticulo = u.FirstOrDefault();
            }


            string pathImg = "../../Files/";


            ViewBag.NombreArticulo = lst;
            ViewBag.RutaImagen     = pathImg;
            return(View());
        }
        public ActionResult SaveArticulo(ArchivoViewModel mdel)
        {
            int      ses       = (int)Session["idusu"];
            string   nameimage = mdel.Imagen.FileName;
            DateTime today     = DateTime.Now;

            string RutaSitio = Server.MapPath("~/");
            string pathImg   = Path.Combine(RutaSitio + "/Files/" + nameimage);

            if (!ModelState.IsValid)
            {
                return(View("NewArticle", mdel));
            }

            using (cursomvcEntities db = new cursomvcEntities())
            {
                articulo oArticulo = new articulo();
                oArticulo.idState     = 1;
                oArticulo.nombre      = mdel.Nombre;
                oArticulo.descripcion = mdel.Descripcion;
                oArticulo.fecha       = today;
                oArticulo.nombreImg   = nameimage;
                oArticulo.idUsuario   = ses;

                db.articulo.Add(oArticulo);
                db.SaveChanges();
            }

            mdel.Imagen.SaveAs(pathImg);
            @TempData["Message"] = "Se ha publicado tu artículo";

            return(RedirectToAction("Index", "Home"));
        }
 public ActionResult Enter(string user, string password)
 {
     try
     {
         using (cursomvcEntities db = new cursomvcEntities())
         {
             var lst = from d in db.user
                       where d.email == user && d.password == password && d.idState == 1
                       select d;
             if (lst.Count() > 0)
             {
                 user oUser = lst.First();
                 Session["User"] = oUser;
                 return(Content("1"));
             }
             else
             {
                 return(Content("Usuario invalido :("));
             }
         }
     }
     catch (Exception ex)
     {
         return(Content("Ocurrio un error :( " + ex.Message));
     }
 }
        public ActionResult Index()
        {
            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
            }


            List <ArticleTableViewModel> lst = null;

            using (cursomvcEntities db = new cursomvcEntities())
            {
                lst = (from t in db.articulo
                       where t.idState == 1
                       orderby t.fecha
                       select new ArticleTableViewModel
                {
                    Nombre = t.nombre,
                    Id = t.id
                }).ToList();
            }



            return(View(lst));
        }
        public ActionResult VerifyComplete()
        {
            string value = Request.QueryString["tk"];
            int    idk   = Convert.ToInt32(Request.QueryString["n"]);

            if (value != "")
            {
                using (var db = new cursomvcEntities())
                {
                    var activada = from d in db.user where d.tokenCuenta == value && d.IdState == 2 && d.Id == idk select d.IdState;

                    if (activada.Contains(2))
                    {
                        var oUser = db.user.Find(idk);
                        oUser.IdState = 1;

                        db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        return(View());
                    }


                    else
                    {
                        return(Redirect(Url.Content("~/Access/")));
                    }
                }
            }
            else
            {
                return(Redirect(Url.Content("~/Access/")));
            }
        }
        // GET: User
        public ActionResult Index()
        {
            try
            {
                List <ListarUserViewModel> lst = null;
                using (cursomvcEntities db = new cursomvcEntities())
                {
                    lst = (from d in db.user
                           where d.idStates == 1
                           orderby d.email
                           select new ListarUserViewModel
                    {
                        Email = d.email,
                        Id = d.id,
                        Edad = d.edad
                    }).ToList();

                    return(View(lst));
                }
            }
            catch (Exception ex)
            {
                return(Content("hay un error"));
            }
        }
Exemple #7
0
        public ActionResult Edit(EditUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new cursomvcEntities())
            {
                var oUser = db.user.Find(model.Id);
                oUser.email = model.Email;
                oUser.edad  = model.Edad;

                if (model.Password != null && model.Password.Trim() != "")
                {
                    oUser.password = model.Password;
                }

                db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }


            return(Redirect(Url.Content("~/User/")));
        }
        public ActionResult Delete(int id)
        {
            using (var db = new cursomvcEntities())
            {
                var oUser = db.user.Find(id);
                oUser.idStates = 0;

                db.Entry(oUser).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            return(Content("1"));
        }
Exemple #9
0
        public ActionResult Edit(int Id)
        {
            EditUserViewModel model = new EditUserViewModel();

            using (var db = new cursomvcEntities())
            {
                var oUser = db.users.Find(Id);
                model.Edad  = (int)oUser.edad;
                model.Email = oUser.email;
                model.Id    = oUser.Id;
            }
            return(View(model));
        }
        // GET: Access
        public ActionResult Index()
        {
            HttpContext.Application["verifyAccount"] = 2;
            List <ArticleTableViewModel> lst = null;

            using (cursomvcEntities db = new cursomvcEntities())
            {
                lst = (from t in db.articulo
                       where t.idState == 1
                       orderby t.fecha
                       select new ArticleTableViewModel
                {
                    Nombre = t.nombre,
                    Id = t.id
                }).ToList();
            }
            return(View(lst));
        }
Exemple #11
0
        // GET: User
        public ActionResult Index()
        {
            List <UserTableViewModel> lst = null;

            using (cursomvcEntities db = new cursomvcEntities())
            {
                lst = (from d in db.users
                       where d.idState == 1
                       orderby d.email
                       select new UserTableViewModel
                {
                    Email = d.email,
                    Id = d.Id,
                    Edad = d.edad
                }).ToList();
            }
            return(View(lst));
        }
        public ActionResult Enter(string user, string pass)
        {
            try
            {
                string ePass = Encrypt.GetSHA256(pass);
                using (cursomvcEntities db = new cursomvcEntities())
                {
                    var lst = from usu in db.user
                              where usu.email == user && usu.password == ePass && usu.IdState == 1
                              select usu;

                    var lst2 = from usu in db.user
                               where usu.email == user && usu.password == ePass && usu.IdState == 1
                               select usu.email;

                    var lst3 = from usu in db.user
                               where usu.email == user && usu.password == ePass && usu.IdState == 1
                               select usu.nombre;

                    var lst4 = from usu in db.user
                               where usu.email == user && usu.password == ePass && usu.IdState == 1
                               select usu.Id;

                    if (lst.Count() > 0)
                    {
                        Session["user"]   = lst.First();
                        Session["email"]  = lst2.First();
                        Session["nombre"] = lst3.First();
                        Session["idusu"]  = lst4.First();

                        return(Content("1"));
                    }
                    else
                    {
                        return(Content("Usuario Inválido. O cuenta no activada"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Content("Ocurrio un error :(" + ex.Message));
            }
        }
        public ActionResult Add(UserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new cursomvcEntities())
            {
                user oUser = new user();
                oUser.email    = model.Email;
                oUser.idStates = 1;
                oUser.password = model.Password;
                oUser.edad     = model.Edad;

                db.user.Add(oUser);
                db.SaveChanges();
            }
            return(Redirect(Url.Content("~/user/")));
        }
        // GET: User

        public ActionResult Index()
        {
            int w = Convert.ToInt32(Session["idusu"]);
            List <UserTableViewModel> lst = null;

            using (cursomvcEntities db = new cursomvcEntities())
            {
                lst = (from t in db.user
                       where t.Id == w
                       select new UserTableViewModel
                {
                    Email = t.email,
                    Id = t.Id,
                    Edad = t.edad,
                    Nombre = t.nombre
                }).ToList();
            }

            return(View(lst));
        }
Exemple #15
0
        public override bool IsValid(object value)
        {
            using (cursomvcEntities db = new cursomvcEntities())
            {
                var lst = from t in db.user where t.email == value.ToString() select value.ToString();

                List <string> miLista = new List <string>();
                foreach (var item in lst)
                {
                    miLista.Add(item.ToString());
                }

                if (miLista.Contains(value.ToString()))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemple #16
0
        public ActionResult Add(UserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (cursomvcEntities db = new cursomvcEntities())
            {
                user oUser = new user
                {
                    idState  = 1,
                    email    = model.Email,
                    edad     = model.Edad,
                    password = model.Password
                };

                db.user.Add(oUser);
                db.SaveChanges();
            }

            return(Redirect(Url.Content("~/User/")));
        }
        public ActionResult CreateAccount(UserAddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string      body           = "";
            VerifyEmail objVerifyEmail = new VerifyEmail();

            try
            {
                using (var db = new cursomvcEntities())
                {
                    user oUser = new user();
                    oUser.IdState     = 2; //1-Activo 2-Activacion Pendiente 3-Eliminado
                    oUser.nombre      = model.Nombre;
                    oUser.email       = model.Email;
                    oUser.password    = Encrypt.GetSHA256(model.Password);
                    oUser.edad        = model.Edad;
                    oUser.tokenCuenta = Encrypt.genTok(model.Email);

                    db.user.Add(oUser);
                    db.SaveChanges();

                    string c = "\"";


                    body = @"
                <body>
	                <style>
                      h3{color:default;}
                      h4{color:lightgreen;}
                    </style>
 
                 <div>   
    
                 <h3>Hola " + oUser.nombre + @".</h3>
                   <p>Gracias por unirte a nuestro Blog. Para hacer uso de nuestra plataforma por favor da clic en el enlace para verificar tu cuenta.</p>
                      <div align=" + c + "center" + c + @">
                      <a href=" + c + "https://*****:*****@">Activar Cuenta</a>
                       
                        <br>
                        <br>
                        <div align=" + c + "left" + c + @">
                        Ricardo Alcántara Castro<br>
                        5561086391 <br>
                        Ingeniero en Computación
                    </div>
                 </body>
                ";

                    objVerifyEmail.sendMail(oUser.email, "Activar Cuenta", body);
                }
                HttpContext.Application["verifyAccount"] = 1;

                return(Redirect(Url.Content("~/Access/Verify/")));
            }
            catch (Exception ex)
            {
                return(Redirect(Url.Content("~/Access/") + ex.Message));
            }
        }
        public ActionResult RecuperarPass(string email)
        {
            string      body           = "";
            VerifyEmail objVerifyEmail = new VerifyEmail();
            user        oUser          = new user();

            try
            {
                using (cursomvcEntities db = new cursomvcEntities())
                {
                    try
                    {
                        var lst = from usu in db.user
                                  where usu.email == email && usu.IdState == 1   //Tiene que ser un usuario con cuenta activada
                                  select usu.Id;

                        Random cod = new Random(Convert.ToInt32(lst.First()));
                        int    n   = cod.Next(1000, 1000000);

                        var okUser = db.user.Find(Convert.ToInt32(lst.First()));
                        okUser.password        = Encrypt.GetSHA256(n.ToString());
                        db.Entry(okUser).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();

                        int codigo = n;

                        if (lst.Count() > 0)
                        {
                            //Mandas el correo

                            string c = "\"";


                            body = @"
                        <body>
	                        <style>
                              h3{color:default;}
                              h4{color:lightgreen;}
                            </style>
 
                         <div>   
    
                         <h3>Hola " + okUser.nombre + @".</h3>
                           <p>Damos seguimiento a la recuperación de tu contraseña. Podrás acceder a nuestro blog con el siguiente código.</p>
                            <p>Código de Acceso: " + codigo + @"</p>  
                         </body>
                        ";

                            objVerifyEmail.sendMail(email, "Recuperar Contraseña", body);

                            return(Content("1"));
                        }
                        else
                        {
                            return(Content("El correo proporcionado no se encuentra registrado en nuestro Blog"));
                        }
                    }
                    catch (Exception d)
                    {
                        return(Content("El correo proporcionado no se encuentra registrado en nuestro Blog"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Content("Ocurrio un error :(" + ex.Message));
            }
        }