예제 #1
0
        public ActionResult Index()
        {
            ViewData["loginModal"] = -100;
            ViewData["Username"]   = User.Identity.Name;
            if (User.Identity.Name == null)
            {
                FormsAuthentication.SignOut();
            }

            UsersDatabaseEntities entity = new UsersDatabaseEntities();

            UserDBAccess db = new UserDBAccess();

            //If the user's data is null

            //In other words auto logged in

            if (SessionVariables.UserData == null)

            {
                //get the user's data

                SessionVariables.UserData = db.GetUserInfoByName(User.Identity.Name);
            }

            //set the users id
            int id = SessionVariables.UserData.Id;
            //check term of use agreements
            //0 = false 1=true
            int agree = Convert.ToInt32(entity.AgreedTermsUseFunc(id).FirstOrDefault());

            //redirect to agree to terms of use
            if (agree == 0)
            {
                return(Redirect("/User/TermsAgree"));
            }
            //check for friend requests
            var requests = entity.CheckFriendRequests(id);
            //Search for user friends and return their info by the user's id
            var data = entity.GetUserFriends(id).ToList();

            //Get links data
            List <GetUserSocialLinks_Result> links = entity.GetUserSocialLinks(id).ToList();

            //Set view Data
            ViewBag.requests = requests;
            ViewBag.friends  = data;
            ViewBag.Links    = links;
            return(View());
        }
        public ActionResult UserPage(string userName)
        {
            //get user data
            ViewData["loginModal"] = -100;
            ViewData["UserLog"]    = true;
            if (User.Identity.Name != null || User.Identity.Name != "")
            {
                ViewData["UserLoggedIn"] = true;
                ViewData["Username"]     = User.Identity.Name;
            }
            else
            {
                ViewData["Username"] = null;
            }
            //set the looked up user name
            ViewData["UserLookedUp"] = userName;
            //get searched user
            UsersDatabaseEntities entity = new UsersDatabaseEntities();
            UserDBAccess          db     = new UserDBAccess();

            //get user info by name
            SessionVariables.UserPage = db.GetUserInfoByName(userName);

            //set the users id
            int id = SessionVariables.UserPage.Id;

            //Search for user friends and return their info by the user's id
            var friends = entity.GetUserFriends(id).ToList();
            //Get links data
            List <GetUserSocialLinks_Result> links = entity.GetUserSocialLinks(id).ToList();

            //Set view Data
            ViewBag.friends = friends;
            ViewBag.Links   = links;
            return(View());
        }
        public ActionResult NewUserLink(FormCollection form)
        {
            ViewData["loginModal"] = -100;
            ViewData["UserLog"]    = true;
            if (User.Identity.Name != null || User.Identity.Name != "")
            {
                ViewData["UserLoggedIn"] = true;
                ViewData["Username"]     = User.Identity.Name;
            }
            else
            {
                ViewData["Username"] = null;
            }
            UserDBAccess          db       = new UserDBAccess();
            UsersDatabaseEntities entities = new UsersDatabaseEntities();
            int userID = db.GetUserInfoByName(User.Identity.Name).Id;
            //check user input
            Boolean check;
            string  input;
            int     mslid;

            linkEdit.NumLinks++;

            //make sure link is valid
            if (form["Url"].ToString() != null)
            {
                check = inputValidation.IsValidUrl(form["Url"].ToString());
            }
            else
            {
                check = false;
            }

            //url input of user and mslid selection
            input = form["Url"].ToString();
            mslid = Convert.ToInt32(form["Social"].ToString());

            /*
             * This creates a new row if not already made.
             * This also updates an mslid if already in database.
             */
            List <GetUserSocialLinks_Result> links = entities.GetUserSocialLinks(userID).ToList();
            Boolean found = false;

            //Check if mslid is used already and if link is used already
            foreach (GetUserSocialLinks_Result link in links)
            {
                if (link.userUrl == input || link.id == mslid)
                {
                    found = true;
                }
            }

            //if user input not found already in database
            if (!found)
            {
                entities.NewUCLTProc(userID, mslid, input);
            }

            return(Redirect("/Home/Index"));
        }