protected void ViewCommentsEvent(object sender, EventArgs e) { PostCard parentPost = sender as PostCard; int postId = parentPost.PostId; Session["CurrentParentPost"] = postId; Exception ex = null; foreach (RepeaterItem i in RepeaterPosts.Items) { PostCard pc = i.FindControl("postCard") as PostCard; if (pc.PostId != postId) { i.Visible = false; } } divComments.Visible = true; List <(string, dynamic, Type)> filter = new List <(string, dynamic, Type)>(); filter.Add(DBObjCreator.CreateFilter("CommentPostId", postId, typeof(int))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_FindCommentsForPost", ref ex, filter); List <Comment> comments = new List <Comment>(); records.ForEach(r => comments.Add(DBObjCreator.CreateObj <Comment>(r, typeof(Comment)))); repeaterComments.DataSource = comments; repeaterComments.DataBind(); }
protected void populateTags() { List <Tag> tags = new List <Tag>(); if (ViewState["TagList"] == null) { Exception ex = null; List <(string, dynamic, Type)> filter = new List <(string, dynamic, Type)>(); filter.Add(DBObjCreator.CreateFilter("PostId", PostId, typeof(int))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetTagsByPost", ref ex, filter); records.ForEach(r => tags.Add(DBObjCreator.CreateObj <Tag>(r, typeof(Tag)))); ViewState["TagList"] = tags; } tags = (List <Tag>)ViewState["TagList"]; foreach (Tag t in tags) { var tc = (TagControl)Page.LoadControl("TagControl.ascx"); tc.Text = t.TagText; AddTag(t.TagText); tc.ButtonClick += new EventHandler(Tag_ButtonClick); ph.Controls.Add(tc); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["Username"] == null && Session["Guest"] == null) { Response.Redirect("Login.aspx"); } if (Session["Username"] != null) { string username = Session["Username"].ToString(); UserService.UserService proxy = new UserService.UserService(); bool verified = proxy.IsUserVerified(username); if (!verified) { Response.Redirect("Verification.aspx?mail=false"); } } Exception ex = null; if (Session["Username"] != null) { currentUsername = (string)Session["Username"]; List <(string, dynamic, Type)> filter = new List <(string, dynamic, Type)>(); filter.Add(DBObjCreator.CreateFilter("Username", currentUsername, typeof(string))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetUser", ref ex, filter); List <User> newUser = new List <User>(); records.ForEach(r => newUser.Add(DBObjCreator.CreateObj <User>(r, typeof(User)))); currentUser = newUser[0]; Session["CurrentUserObj"] = currentUser; } if (!IsPostBack) { Session["AdvSearch"] = false; if (Session["Username"] != null) { Greeting.InnerText = "All Posts"; InitializeTrendingList(); InitializeFollowList(); InitializeAllPostsList(); repeaterFollow.Visible = false; Session["CurrentView"] = ALL; } if (Session["Guest"] != null) { Greeting.InnerText = "All Posts"; InitializeAllPostsList(); InitializeTrendingList(); btnFollowPosts.Visible = false; Session["CurrentView"] = ALL; divCreateComment.Visible = false; btnNewPost.Visible = false; } } SetupPostCardEvents(); }
private void InitializeAllPostsList() { Exception ex = null; List <object[]> records = DBObjCreator.ReadDBObjs("TP_GetAllPosts", ref ex); List <Post> posts = new List <Post>(); records.ForEach(r => posts.Add(DBObjCreator.CreateObj <Post>(r, typeof(Post)))); Session["AllPosts"] = posts; repeaterAll.DataSource = posts; repeaterAll.DataBind(); }
[HttpGet("GetUserPostsFiltered/{Username}/{Likes?}/{Time?}/{Image?}")] //https://localhost:44312/api/Post/GetUserPostsFiltered/TestUser/20/11_20_2020-11_21_2020/1 public List <Post> GetUsersPosts(string Username, int Likes = -1, string Time = "No Time", int Image = -1) { Exception ex = null; List <(string field, dynamic value, Type type)> filter = new List <(string field, dynamic value, Type type)>(); filter.Add(DBObjCreator.CreateFilter("Username", $"{Username}", typeof(string))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetUsersPosts", ref ex, filter); List <Post> posts = new List <Post>(); records.ForEach(o => posts.Add(DBObjCreator.CreateObj <Post>(o, typeof(Post)))); if (Likes >= 0) { posts.RemoveAll(p => p.Likes < Likes); } if (Image > -1) { if (Image == 1) //True, remove posts without images { posts.RemoveAll(p => string.IsNullOrEmpty(p.PostPhoto)); } else // False, remove posts with images { posts.RemoveAll(p => !string.IsNullOrEmpty(p.PostPhoto)); } } if (!Time.Equals("No Time")) { Time = Time.Replace('_', '/'); //C# api's cant handle encoded forward slashes easily so need to use _ and convert them to slashes DateTime dateOne; DateTime dateTwo; string[] times = Time.Split("-"); if (times.Length < 2) { return(null); } if (!DateTime.TryParse(times[0], out dateOne)) { return(null); } if (!DateTime.TryParse(times[1], out dateTwo)) { return(null); } posts.RemoveAll(p => DateTime.Parse(p.PostDate) < dateOne || DateTime.Parse(p.PostDate) > dateTwo); } return(posts); }
[HttpGet("GetUserFollows/{Username}")] //https://localhost:44312/api/User/GetUserFollows/TestUser public List <Follow> GetUsersFollows(string Username) { Exception ex = null; List <(string field, dynamic value, Type type)> filter = new List <(string field, dynamic value, Type type)>(); filter.Add(DBObjCreator.CreateFilter("Username", $"{Username}", typeof(string))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetUserFollows", ref ex, filter); List <Follow> follows = new List <Follow>(); records.ForEach(o => follows.Add(DBObjCreator.CreateObj <Follow>(o, typeof(Follow)))); return(follows); }
private void InitializeFollowList() { Exception ex = null; List <(string, dynamic, Type)> filter = new List <(string, dynamic, Type)>(); filter.Add(DBObjCreator.CreateFilter("Username", currentUsername, typeof(string))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetPostsByFollow", ref ex, filter); List <Post> usersPosts = new List <Post>(); records.ForEach(r => usersPosts.Add(DBObjCreator.CreateObj <Post>(r, typeof(Post)))); List <Post> uniquePosts = usersPosts.GroupBy(p => p.Id).Select(id => id.First()).ToList(); //Select only the first occurence of a post ID repeaterFollow.DataSource = uniquePosts; repeaterFollow.DataBind(); }
private void InitializeTrendingList() { Exception ex = null; List <(string, dynamic, Type)> filter = new List <(string, dynamic, Type)>(); filter.Add(DBObjCreator.CreateFilter("Trending", TRENDING, typeof(bool))); List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetPostsByTrending", ref ex, filter); List <Post> usersPosts = new List <Post>(); records.ForEach(r => usersPosts.Add(DBObjCreator.CreateObj <Post>(r, typeof(Post)))); //Needs to be changed to be trending or something List <Post> uniquePosts = usersPosts.GroupBy(p => p.Id).Select(id => id.First()).ToList(); //Select only the first occurence of a post ID repeaterTrending.DataSource = uniquePosts; repeaterTrending.DataBind(); }