//
        // GET: /Settings/

        public ActionResult Save(SettingsModel sm)
        {
            user currentUser = Session["user"] as user;
            using(var conn = new ifollowdatabaseEntities4())
            {
                currentUser = conn.users.First(u => u.id == currentUser.id);
                if (currentUser != null)
                {
                    currentUser.firstName = sm.firstName;
                    currentUser.lastName = sm.lastName;
                    currentUser.city = sm.city;
                    currentUser.country = sm.country;
                    currentUser.birthdate = sm.birthDate;

                    try
                    {
                        conn.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }
                }
            }
            return RedirectToAction("Settings","Wall");
        }
Beispiel #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                using (var entities = new ifollowdatabaseEntities4())
                {
                    user newUser = new user();
                    newUser.email            = model.UserName;
                    newUser.password         = model.Password;
                    newUser.registrationDate = DateTime.UtcNow.Date;
                    char[]   delimiters     = { '@' };
                    string[] nameComponents = model.UserName.Split(delimiters);
                    newUser.firstName = nameComponents[0];
                    newUser.lastName  = @"";

                    int count = entities.users.Count();
                    newUser.id = count + 1;

                    entities.users.Add(newUser);
                    try
                    {
                        entities.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("", e);
                    }

                    return(RedirectToAction("Index", "Home"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Profile(string user)
        {
            long         currentUserId;
            ProfileModel pm = new ProfileModel();

            if (user == "current")
            {
                currentUserId = (Session["user"] as user).id;
            }
            else
            {
                currentUserId = (long)Convert.ToDouble(user);
            }

            using (var entities = new ifollowdatabaseEntities4())
            {
                user currentUser = entities.users.First(u => u.id == currentUserId);
                pm.userName       = currentUser.firstName;
                pm.postsCount     = currentUser.posts.Count();
                pm.followersCount = currentUser.followers.Count();
                pm.followedCount  = currentUser.followers1.Count();
                pm.elements.BuildFromImagesAndPosts(currentUser.posts, currentUser.images);
            }
            ViewBag.Message = "Your profile page.";
            return(PartialView("_ProfilePage", pm));
        }
        public ActionResult Follow(string submit)
        {
            user currentUser = Session["user"] as user;
            long uid         = (long)Convert.ToDouble(submit);

            using (var entities = new ifollowdatabaseEntities4())
            {
                currentUser = entities.users.First(u => u.id == currentUser.id);
                follower fol = new follower();
                fol.followedId = uid;
                fol.followerId = currentUser.id;
                entities.followers.Add(fol);

                try
                {
                    entities.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
            }

            return(RedirectToAction("Followers", "Wall"));
        }
Beispiel #5
0
        //
        // GET: /Main/

        public ActionResult MainPage()
        {
            user           currentUser = Session["user"] as user;
            WallPostsModel wpm         = new WallPostsModel();

            using (var entities = new ifollowdatabaseEntities4())
            {
                currentUser = entities.users.First(u => u.id == currentUser.id);
                wpm.BuildFromImagesAndPosts(currentUser.posts, currentUser.images);
            }

            return(View(wpm));
        }
Beispiel #6
0
        public ActionResult Profile()
        {
            user         currentUser = Session["user"] as user;
            ProfileModel pm          = new ProfileModel();

            pm.userName = currentUser.firstName;

            using (var entities = new ifollowdatabaseEntities4())
            {
                currentUser       = entities.users.First(u => u.id == currentUser.id);
                pm.postsCount     = currentUser.posts.Count();
                pm.followersCount = currentUser.followers.Count();
                pm.followedCount  = currentUser.followers1.Count();
                pm.elements.BuildFromImagesAndPosts(currentUser.posts, currentUser.images);
            }
            ViewBag.Message = "Your profile page.";
            return(PartialView("_ProfilePage", pm));
        }
Beispiel #7
0
        public ActionResult Login(user model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                using (var entities = new ifollowdatabaseEntities4())
                {
                    string email    = model.email;
                    string password = model.password;

                    // Now if our password was enctypted or hashed we would have done the
                    // same operation on the user entered password here, But for now
                    // since the password is in plain text lets just authenticate directly

                    bool userValid = entities.users.Any(user => user.email == email && user.password == password);

                    // User found in the database
                    if (userValid)
                    {
                        FormsAuthentication.SetAuthCookie(email, false);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            Session["user"] = entities.users.First(e => e.email == model.email && e.password == model.password);
                            return(RedirectToAction("MainPage", "Wall"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return(View("~/Views/Home/Index.cshtml", model));
        }
        public ActionResult Settings()
        {
            ViewBag.Message = "Your contact page.";

            SettingsModel sm          = new SettingsModel();
            user          currentUser = Session["user"] as user;

            using (var conn = new ifollowdatabaseEntities4())
            {
                currentUser = conn.users.First(u => u.id == currentUser.id);
                if (currentUser != null)
                {
                    sm.firstName = currentUser.firstName;
                    sm.lastName  = currentUser.lastName;
                    sm.country   = currentUser.country;
                    sm.city      = currentUser.city;
                    //sm.birthDate = (System.DateTime)currentUser.birthdate;
                }
            }

            return(PartialView("_SettingsModal"));
        }
        //
        // GET: /Main/

        public ActionResult MainPage()
        {
            user           currentUser = Session["user"] as user;
            WallPostsModel wpm         = new WallPostsModel();

            using (var entities = new ifollowdatabaseEntities4())
            {
                currentUser = entities.users.First(u => u.id == currentUser.id);

                ICollection <post>  posts     = currentUser.posts;
                ICollection <image> images    = currentUser.images;
                DbSet <follower>    followers = entities.followers;

                foreach (follower f in followers)
                {
                    if (f.followerId == currentUser.id)
                    {
                        using (var conn = new ifollowdatabaseEntities4())
                        {
                            user ff = conn.users.First(u => u.id == f.followedId);
                            foreach (image i in ff.images)
                            {
                                images.Add(i);
                            }

                            foreach (post p in ff.posts)
                            {
                                posts.Add(p);
                            }
                        }
                    }
                }

                wpm.BuildFromImagesAndPosts(currentUser.posts, currentUser.images);
            }

            return(View(wpm));
        }
Beispiel #10
0
        public ActionResult Upload(UploadFileModel fileModel)
        {
            if (ModelState.IsValid)
            {
                image newImage    = null;
                user  currentUser = Session["user"] as user;

                if (fileModel != null && fileModel.File != null)
                {
                    string timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff") + ".png";
                    var    path      = Path.Combine(Server.MapPath("~/Images/UserPhotos"), timestamp);
                    fileModel.File.SaveAs(path);
                    fileModel.Path = timestamp;

                    using (var entities = new ifollowdatabaseEntities4())
                    {
                        newImage           = new image();
                        newImage.isAvatar  = false;
                        newImage.isDeleted = false;
                        newImage.url       = timestamp;

                        int count = entities.images.Count();
                        newImage.id      = count + 1;
                        newImage.ownerId = currentUser.id;

                        entities.images.Add(newImage);
                        try
                        {
                            entities.SaveChanges();
                        }
                        catch (DbEntityValidationException dbEx)
                        {
                            foreach (var validationErrors in dbEx.EntityValidationErrors)
                            {
                                foreach (var validationError in validationErrors.ValidationErrors)
                                {
                                    Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                                }
                            }
                        }
                    }
                }

                using (var entities = new ifollowdatabaseEntities4())
                {
                    post newPost = new post();

                    newPost.dateCreated = DateTime.UtcNow;
                    int count = entities.posts.Count();
                    newPost.id = count + 1;

                    if (newImage != null)
                    {
                        newPost.imageId = newImage.id;
                    }

                    newPost.ownerId   = currentUser.id;
                    newPost.message   = fileModel.Message;
                    newPost.rating    = 0;
                    newPost.isDeleted = false;

                    entities.posts.Add(newPost);
                    try
                    {
                        entities.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }
                }
                return(RedirectToAction("MainPage", "Wall"));
            }

            return(RedirectToAction("MainPage", "Wall"));
        }