Exemplo n.º 1
0
        public ActionResult Create(Tweet nuevo)
        {
            BDTwitterEntities1 db = new BDTwitterEntities1();

            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    //Tweet nuevo = new Tweet();
                    nuevo.PostDate = DateTime.Now;
                    //nuevo.Post = collection["Post"];
                    nuevo.User = db.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault();
                    db.AddToTweets(nuevo);
                    db.SaveChanges();

                    List <Tweet>       tweets        = new List <Tweet>();
                    BDTwitterEntities1 bd            = new BDTwitterEntities1();
                    string             NombreUsuario = User.Identity.Name;
                    var tweet = from t in bd.Tweets where t.User.UserName == NombreUsuario && t.PostDate < DateTime.Now orderby t.PostDate descending select t;
                    ViewData["tweet"] = tweet.ToList();
                    return(View("Feed", tweet.ToList()));
                }
            }
            catch (Exception e) { }

            return(View("Index", null));
        }
Exemplo n.º 2
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                {
                    BDTwitterEntities1 db = new BDTwitterEntities1();

                    User u = new User();
                    u = (from c in db.Users where User.Identity.Name == c.UserName select c).SingleOrDefault();

                    if (u != null)
                    {
                        u.Password = model.NewPassword;
                        db.SaveChanges();
                    }

                    return(RedirectToAction("ChangePasswordSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", "Password Invalida");
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult PostPage(string name)
        {
            List <Tweet>       tweets = new List <Tweet>();
            BDTwitterEntities1 bd     = new BDTwitterEntities1();
            var tweet = from t in bd.Tweets where t.User.UserName == name && t.PostDate < DateTime.Now orderby t.PostDate descending select t;

            ViewData["tweet"] = tweet.ToList();
            return(View("PostPage", tweet.ToList()));
        }
Exemplo n.º 4
0
        public ActionResult Feed()
        {
            List <Tweet>       tweets        = new List <Tweet>();
            BDTwitterEntities1 bd            = new BDTwitterEntities1();
            string             NombreUsuario = User.Identity.Name;
            var tweet = from t in bd.Tweets where t.User.UserName == NombreUsuario && t.PostDate < DateTime.Now orderby t.PostDate descending select t;

            ViewData["tweet"] = tweet.ToList();
            return(View("Feed", tweet.ToList()));
        }
Exemplo n.º 5
0
        public ActionResult seguirUser(int followed)
        {
            BDTwitterEntities1 bd = new BDTwitterEntities1();

            mvcTwitter.Models.User u = new User();

            if (followed != 0)
            {
                bd.spSetFolloweds(UsuarioLogueado.id, followed);
            }

            return(RedirectToAction("Usuario"));
        }
Exemplo n.º 6
0
        public ActionResult Post(string post)
        {
            if (User.Identity.IsAuthenticated)
            {
                BDTwitterEntities1 db = new BDTwitterEntities1();

                var user = db.Users.Where(u => u.UserName == User.Identity.Name).Single();

                Tweet tweet = new Tweet();
                tweet.Post     = post;
                tweet.PostDate = DateTime.Now;

                user.Tweets.Add(tweet);

                db.SaveChanges();
            }
            return(RedirectToAction("Feed"));
        }
Exemplo n.º 7
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                //   MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                //  if (createStatus == MembershipCreateStatus.Success)
                // {
                BDTwitterEntities1 db = new BDTwitterEntities1();

                User u = new User();
                u = (from c in db.Users where model.UserName == c.UserName select c).SingleOrDefault();

                if (u == null)
                {
                    u = new Models.User();
                    string password;
                    password = model.Password;

                    if (password.Length > 50)
                    {
                        password = password.Substring(0, 50);
                    }

                    u.UserName = model.UserName;
                    u.Password = model.Password;
                    db.AddToUsers(u);
                    db.SaveChanges();
                }

                FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                return(RedirectToAction("Index", "Home"));
                //}
                //else
                //{
                //    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                //}
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemplo n.º 8
0
        public bool validarUser(string nombre, string pass)
        {
            BDTwitterEntities1 db = new BDTwitterEntities1();

            //Models.User[] usuarios = db.Users.Select("Username='******' ' and password='******'").Single();
            Models.User u = new Models.User();
            u = (from c in db.Users where c.UserName == nombre && c.Password == pass select c).SingleOrDefault();

            if (u != null)
            {
                UsuarioLogueado = u;
                return(true);
                // ModelState.AddModelError("", "Nombre de usuarios o password incorrecto.");
            }

            // ViewData["tweet"] = tweet;
            //   Session["User"] = ;
            return(false);
        }
Exemplo n.º 9
0
        public ActionResult Usuario()
        {
            BDTwitterEntities1 bd = new BDTwitterEntities1();

            List <Models.User> usuarios = new List <User>();

            if (User.Identity.IsAuthenticated)
            {
                UsuarioLogueado = bd.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault();
                usuarios        = bd.get_NotFollowed(Convert.ToInt32(UsuarioLogueado.id)).ToList();
                //ViewData["listaUsers"] = usuarios;
                ViewData["MensageUser"] = "";
            }
            else
            {
                ViewData["MensajeUser"] = "******";
            }
            return(View(usuarios));
        }
Exemplo n.º 10
0
        public ActionResult Index()
        {
            BDTwitterEntities1  db    = new BDTwitterEntities1();
            IEnumerable <Tweet> tweet = null;

            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    UsuarioLogueado   = db.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault();
                    ViewData["tweet"] = tweet;

                    tweet = (from i in db.Tweets
                             orderby i.PostDate descending
                             select i);
                    return(View(tweet.ToList()));
                }
            }
            catch (Exception) { }

            return(View(tweet));
        }