public List <PostOBJ> GetWall(String requestingEmail, String requestedEmail, String token) { DBConnect objDB = new DBConnect(); List <PostOBJ> myNewsFeed = new List <PostOBJ>(); SqlCommand LoginUser = new SqlCommand(); LoginUser.CommandType = CommandType.StoredProcedure; LoginUser.CommandText = "TP_FindUser"; LoginUser.Parameters.AddWithValue("@Email", requestingEmail); LoginUser.Parameters.AddWithValue("@Password", decode(token)); SqlParameter outputPar = new SqlParameter("@Out", SqlDbType.Int, 50); outputPar.Direction = ParameterDirection.Output; LoginUser.Parameters.Add(outputPar); objDB.GetDataSetUsingCmdObj(LoginUser); //check token to see if user is logged in with same Email and pass string a = LoginUser.Parameters["@Out"].Value.ToString(); if (a.Equals("1")) { SqlCommand GetWall = new SqlCommand(); GetWall.CommandType = CommandType.StoredProcedure; GetWall.CommandText = "TP_GetWall"; GetWall.Parameters.AddWithValue("@Email", requestedEmail); DataSet myWall = objDB.GetDataSetUsingCmdObj(GetWall); foreach (DataRow thisUsersPosts in myWall.Tables[0].Rows) { PostOBJ thisPost = new PostOBJ(); thisPost.EmailOwner = thisUsersPosts["EmailOwner"].ToString(); thisPost.EmailWriter = thisUsersPosts["EmailWriter"].ToString(); thisPost.Content = thisUsersPosts["Content"].ToString(); thisPost.Date = DateTime.Parse(thisUsersPosts["Date"].ToString()); myNewsFeed.Add(thisPost); } List <PostOBJ> SortedList = myNewsFeed.OrderByDescending(o => o.Date).ToList(); return(SortedList); } else { return(myNewsFeed); } }
public List <PostOBJ> GetNewsFeed(String requestingEmail, String requestedEmail, String token) { DBConnect objDB = new DBConnect(); List <PostOBJ> myNewsFeed = new List <PostOBJ>(); SqlCommand LoginUser = new SqlCommand(); LoginUser.CommandType = CommandType.StoredProcedure; LoginUser.CommandText = "TP_FindUser"; LoginUser.Parameters.AddWithValue("@Email", requestingEmail); LoginUser.Parameters.AddWithValue("@Password", decode(token)); SqlParameter outputPar = new SqlParameter("@Out", SqlDbType.Int, 50); outputPar.Direction = ParameterDirection.Output; LoginUser.Parameters.Add(outputPar); objDB.GetDataSetUsingCmdObj(LoginUser); //check token to see if user is logged in with same Email and pass string a = LoginUser.Parameters["@Out"].Value.ToString(); if (a.Equals("1")) { SqlCommand GetFriends = new SqlCommand(); GetFriends.CommandType = CommandType.StoredProcedure; GetFriends.CommandText = "TP_GetFriends"; GetFriends.Parameters.AddWithValue("@Email", requestedEmail); DataSet Friends = objDB.GetDataSetUsingCmdObj(GetFriends); SqlCommand GetPosts = new SqlCommand(); GetPosts.CommandType = CommandType.StoredProcedure; GetPosts.CommandText = "TP_GetPosts"; SqlCommand CheckFollow = new SqlCommand(); CheckFollow.CommandType = CommandType.StoredProcedure; CheckFollow.CommandText = "TP_CheckFollow"; //get my Posts and add them to news feed collection GetPosts.Parameters.AddWithValue("@Email", requestingEmail); DataSet myPosts = objDB.GetDataSetUsingCmdObj(GetPosts); foreach (DataRow thisUsersPosts in myPosts.Tables[0].Rows) { PostOBJ thisPost = new PostOBJ(); thisPost.EmailOwner = thisUsersPosts["EmailOwner"].ToString(); thisPost.EmailWriter = thisUsersPosts["EmailWriter"].ToString(); thisPost.Content = thisUsersPosts["Content"].ToString(); thisPost.Date = DateTime.Parse(thisUsersPosts["Date"].ToString()); myNewsFeed.Add(thisPost); } foreach (DataRow record in Friends.Tables[0].Rows) { GetPosts.Parameters.Clear(); GetPosts.Parameters.AddWithValue("@Email", record["Person2"].ToString()); DataSet Posts = objDB.GetDataSetUsingCmdObj(GetPosts); foreach (DataRow thisUsersPosts in Posts.Tables[0].Rows) { CheckFollow.Parameters.Clear(); CheckFollow.Parameters.AddWithValue("@Email1", record["Person1"].ToString()); CheckFollow.Parameters.AddWithValue("@Email2", record["Person2"].ToString()); SqlParameter outputPar1 = new SqlParameter("@found", SqlDbType.Int, 50); outputPar1.Direction = ParameterDirection.Output; CheckFollow.Parameters.Add(outputPar1); objDB.GetDataSetUsingCmdObj(CheckFollow); if (CheckFollow.Parameters["@found"].Value.ToString() == "1") { PostOBJ thisPost = new PostOBJ(); thisPost.EmailOwner = thisUsersPosts["EmailOwner"].ToString(); thisPost.EmailWriter = thisUsersPosts["EmailWriter"].ToString(); thisPost.Content = thisUsersPosts["Content"].ToString(); thisPost.Date = DateTime.Parse(thisUsersPosts["Date"].ToString()); myNewsFeed.Add(thisPost); } } } List <PostOBJ> SortedList = myNewsFeed.OrderByDescending(o => o.Date).ToList(); return(SortedList); } else { return(myNewsFeed); } }