Esempio n. 1
0
        // GET: Users/Details/5
        public ActionResult Details2(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserAndPosts user = new UserAndPosts();

            user.user  = db.Users.Find(id);
            user.posts = (from x in db.UserPosts where x.User_ID == id select x).ToList();

            /*
             * There are several situations when it comes to being able to follow
             * and see if you are already following. We also have to consider whether
             * a user is viewing their own page in which case the option to follow
             * or unfollow shouldn't appear as a user can't follow themseves
             */

            //No one is logged in or user is viewing themselves
            if (Session["username"] == null ||
                Session["username"].ToString() == user.user.Username)
            {
                user.following = "invalid";
            }
            //User is viewing another profile and is logged in
            else
            {
                int sessionID = (int)Session["id"];
                //string following = db.FollowLists.Where(x => (x.FolloweeID == id) && (x.FollowerID == sessionID)).Select(x => x.ID).FirstOrDefault().ToString() ?? "Invalid";
                if ((db.FollowLists.Where(x => (x.FolloweeID == id) && (x.FollowerID == sessionID)).Select(x => x.ID).FirstOrDefault().ToString() ?? "Invalid") != "Invalid")
                {
                    //There is a following between current user and profile of the user they are o
                    user.following = "following";
                }
                else
                {
                    //They are not following the user profile they are currently on
                    user.following = "unfollowing";
                }
            }

            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
Esempio n. 2
0
        public ActionResult FollowOrUnfollowUser(int newFollowStatus, int loggedInUser, int userProfile)
        {
            //They clicked that they want to follow
            if (newFollowStatus == 1)
            {
                FollowList newEntry = new FollowList();
                newEntry.FollowerID = loggedInUser;
                newEntry.FolloweeID = userProfile;
                db.FollowLists.Add(newEntry);
                db.SaveChanges();
            }
            else //They want to unfollow
            {
                int id = (db.FollowLists.Where(x => (x.FolloweeID == userProfile) && (x.FollowerID == loggedInUser)).Select(x => x.ID)).FirstOrDefault();
                db.FollowLists.Remove(db.FollowLists.Find(id));
                db.SaveChanges();
            }
            UserAndPosts user = new UserAndPosts();

            user.following = "unfollowing";
            return(Json(new { user, Status = "Ok", Error = "" }));
        }
Esempio n. 3
0
        // GET: Users/Details/5
        public ActionResult Details2(int?id, string sortOrder, string currentFilter, int?page, string postAndOrUsername)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserAndPosts user = new UserAndPosts();

            user.user  = db.Users.Find(id);
            user.posts = (from x in db.UserPosts where x.User_ID == id select x).ToList();

            /*
             * There are several situations when it comes to being able to follow
             * and see if you are already following. We also have to consider whether
             * a user is viewing their own page in which case the option to follow
             * or unfollow shouldn't appear as a user can't follow themseves
             */

            //No one is logged in or user is viewing themselves
            if (Session["username"] == null ||
                Session["username"].ToString() == user.user.Username)
            {
                user.following = "invalid";
                if (Session["username"] == null || Session["username"].ToString() == user.user.Username)
                {
                    if (db.LinkedAccounts.Where(x => x.Account1ID == id || x.Account2ID == id).Count() > 0)
                    {
                        LinkedAccount link = db.LinkedAccounts.Where(x => x.Account1ID == id || x.Account2ID == id).Single();
                        if (link.Account1ID == id)
                        {
                            user.otherAccount = db.Users.Find(link.Account2ID);
                        }
                        else
                        {
                            user.otherAccount = db.Users.Find(link.Account1ID);
                        }
                    }
                }
            }
            //User is viewing another profile and is logged in
            else
            {
                int sessionID = (int)Session["id"];
                //int followingint = db.FollowLists.Where(x => (x.FolloweeID == id) && (x.FollowerID == sessionID)).Select(x => x.ID);

                if ((db.FollowLists.Where(x => (x.FolloweeID == id) && (x.FollowerID == sessionID)).Select(x => x.ID)).FirstOrDefault() != 0)
                {
                    //There is a following between current user and profile of the user they are on,
                    //meaning they should get the option to unfollow
                    user.following = "Unfollow";
                }
                else
                {
                    //They are not following the user profile they are currently on.
                    //meaning they should get the option to follow
                    user.following = "Follow";
                }
                user.otherAccount = null;
            }

            //Sorting the Table
            ViewBag.CurrentSort = sortOrder;
            List <string> list = new List <string>();

            list.Add("Post Title");
            list.Add("Username");
            list.Add("Both");
            ViewBag.PostAndOrUsername         = new SelectList(list);
            ViewBag.SelectedPostAndOrUsername = postAndOrUsername;
            ViewBag.DateSortParm     = String.IsNullOrEmpty(sortOrder) ? "date_asc" : "";
            ViewBag.TitleSortParm    = sortOrder == "Title" ? "title_desc" : "Title";
            ViewBag.LikesSortParm    = sortOrder == "Likes" ? "likes_desc" : "Likes";
            ViewBag.DislikesSortParm = sortOrder == "Dislikes" ? "dislikes_desc" : "Dislikes";
            ViewBag.UserNameSortParm = sortOrder == "UserName" ? "userName_desc" : "UserName";
            page = 1;
            switch (sortOrder)
            {
            case "date_asc":
                user.posts = user.posts.OrderBy(p => p.Date_Posted);
                break;

            case "title_desc":
                user.posts = user.posts.OrderByDescending(p => p.Title);
                break;

            case "Title":
                user.posts = user.posts.OrderBy(p => p.Title);
                break;

            case "likes_desc":
                user.posts = user.posts.OrderByDescending(p => p.Likes);
                break;

            case "Likes":
                user.posts = user.posts.OrderBy(p => p.Likes);
                break;

            case "dislikes_desc":
                user.posts = user.posts.OrderByDescending(p => p.Dislikes);
                break;

            case "Dislikes":
                user.posts = user.posts.OrderBy(p => p.Dislikes);
                break;

            default:
                user.posts = user.posts.OrderByDescending(p => p.Date_Posted);
                break;
            }
            //End of sorting the Table

            /* USE FOR PAGING THE TABLE
             * int pageSize = 3;
             * int pageNumber = (page ?? 1);
             */
            return(View(user));
        }