Beispiel #1
0
        public static List <UserContent> HomepagePost(string username)
        {
            if (connect.State == ConnectionState.Open)
            {
                connect.Close();
            }
            connect.Open();

            SqlCommand cmd = new SqlCommand("homepage", connect);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("@userID", SqlDbType.VarChar, 30).Value = username;
            SqlDataReader reader = cmd.ExecuteReader();


            List <UserContent> postList = new List <UserContent>();

            while (reader.Read())
            {
                UserContent post = new UserContent();
                post.contentID    = Convert.ToInt32(reader["contentID"]);
                post.username     = reader["username"].ToString();
                post.privacy      = reader["privacy"].ToString();
                post.DateCreation = Convert.ToDateTime(reader["DateCreation"]);
                post.FileType     = reader["FileType"].ToString();
                post.RawData      = reader["RawData"].ToString();
                post.likes        = Convert.ToInt32(reader["likes"]);
                post.filePath     = reader["filePath"].ToString();
                postList.Add(post);
            }

            connect.Close();
            reader.Close();
            return(postList);
        }
Beispiel #2
0
        public static UserContent GetUserPost(int id)
        {
            if (connect.State == ConnectionState.Open)
            {
                connect.Close();
            }
            connect.Open();
            SqlCommand cmd = new SqlCommand("", connect);

            cmd.CommandText = "select * from UserContent where contentID=@contentID";
            cmd.Parameters.AddWithValue("@contentID", id);
            SqlDataReader reader = cmd.ExecuteReader();
            UserContent   post   = new UserContent();

            if (reader.Read())
            {
                post.contentID    = Convert.ToInt32(reader["contentID"]);
                post.username     = reader["username"].ToString();
                post.privacy      = reader["privacy"].ToString();
                post.DateCreation = Convert.ToDateTime(reader["DateCreation"]);
                post.FileType     = reader["FileType"].ToString();
                post.RawData      = reader["RawData"].ToString();
                post.likes        = Convert.ToInt32(reader["likes"]);
                post.filePath     = reader["filePath"].ToString();
            }

            connect.Close();
            reader.Close();
            return(post);
        }
Beispiel #3
0
        public static List <UserContent> AllPostsOfAUser(string username)
        {
            if (connect.State == ConnectionState.Open)
            {
                connect.Close();
            }
            connect.Open();
            SqlCommand cmd = new SqlCommand("", connect);

            cmd.CommandText = "select * from UserContent where username=@username order by DateCreation DESC";
            cmd.Parameters.AddWithValue("@username", username);
            SqlDataReader reader = cmd.ExecuteReader();

            List <UserContent> postList = new List <UserContent>();

            while (reader.Read())
            {
                UserContent post = new UserContent();
                post.contentID    = Convert.ToInt32(reader["contentID"]);
                post.username     = reader["username"].ToString();
                post.privacy      = reader["privacy"].ToString();
                post.DateCreation = Convert.ToDateTime(reader["DateCreation"]);
                post.FileType     = reader["FileType"].ToString();
                post.RawData      = reader["RawData"].ToString();
                post.likes        = Convert.ToInt32(reader["likes"]);
                post.filePath     = reader["filePath"].ToString();
                postList.Add(post);
            }

            connect.Close();
            reader.Close();
            return(postList);
        }
Beispiel #4
0
        public static List <UserContent> getNonSessionUserPosts(string username, string sessionUser)
        {
            int sessionUserIsFollower = 0;

            if (connect.State == ConnectionState.Open)
            {
                connect.Close();
            }
            connect.Open();
            SqlCommand cmd = new SqlCommand("getNonSessionUserPosts", connect);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add("@username", SqlDbType.VarChar, 30).Value = username;
            if (IsFollowing(sessionUser, username))
            {
                sessionUserIsFollower = 1;
            }
            cmd.Parameters.Add("@sessionUserIsFollowing", SqlDbType.Int).Value = sessionUserIsFollower;
            if (connect.State == ConnectionState.Open)
            {
                connect.Close();
            }
            connect.Open();
            SqlDataReader      r     = cmd.ExecuteReader();
            List <UserContent> posts = new List <UserContent>();

            while (r.Read())
            {
                UserContent post = new UserContent();
                post.contentID    = Convert.ToInt32(r["contentID"]);
                post.username     = r["username"].ToString();
                post.likes        = Convert.ToInt32(r["likes"]);
                post.DateCreation = Convert.ToDateTime(r["DateCreation"]);
                post.privacy      = r["privacy"].ToString();
                post.RawData      = r["RawData"].ToString();
                post.filePath     = r["filePath"].ToString();

                posts.Add(post);
            }
            r.Close();
            connect.Close();

            return(posts);
        }