Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        [HttpPost("DeletePost")] //https://localhost:44312/api/Post/DeletePost/10
        public string DeletePost([FromBody] int postId)
        {
            Exception ex = null;
            List <(string field, dynamic value, Type type)> filter = new List <(string field, dynamic value, Type type)>();

            filter.Add(DBObjCreator.CreateFilter("Id", postId, typeof(int)));
            List <object[]> records = DBObjCreator.ReadDBObjsWithWhere("TP_GetPostsById", ref ex, filter);

            if (records.Count != 1)
            {
                return("Post ID does not exist.");
            }

            List <(bool, int, Exception)> errors = new List <(bool, int, Exception)>();
            bool result = DBObjWriter.DeleteWithWhere("TP_DeletePostById", ref ex, filter);

            if (result)
            {
                return("Post succesfully deleted");
            }
            else
            {
                return("Failed to delete post, please try again later");
            }
        }
Ejemplo n.º 4
0
        [HttpGet("GetUserFollowCount/{Username}")] //https://localhost:44312/api/User/GetUserFollowCount/TestUser
        public int GetUsersFollowCount(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);

            return(records.Count);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        [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);
        }
Ejemplo n.º 8
0
        private void InitializeWebAssets()
        {
            Exception ex = null;
            List <(string, dynamic, Type)> filter = new List <(string, dynamic, Type)>();

            filter.Add(DBObjCreator.CreateFilter("Key", LOGO, typeof(string)));
            List <object[]> records        = DBObjCreator.ReadDBObjsWithWhere("TP_GetAsset", ref ex, filter);
            string          serializedData = (string)records[0][2];

            WebAssetSerializer.DeserializeImage(serializedData, imgLogo);
        }
Ejemplo n.º 9
0
        [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);
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        [HttpPost("CreateComment")] //https://localhost:44312/api/Post/CreateComment
        public string CreateComment(string text, string username, int postId)
        {
            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_GetUser", ref ex, filter);

            if (records.Count != 1)//Username/password combo not valid
            {
                return("Invalid username.");
            }
            Comment newComment = new Comment(-1, username, postId, text);
            List <(bool, int, Exception)> errors = new List <(bool, int, Exception)>();
            bool result = DBObjWriter.GenericWriteToDB <Comment>(newComment, "TP_CreateComment", ref errors, new List <string>()
            {
                "Id"
            });

            return("Comment succesfully created");
        }