Ejemplo n.º 1
0
        protected void rptUserPosts_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Repeater repeater = (e.Item.FindControl("rptComment") as Repeater);

            if (e.CommandName == "Comment")
            {
                TextBox comment    = (e.Item.FindControl("hello") as TextBox);
                var     comt       = comment.Text;
                var     newComment = new BLL.Comment();
                newComment.UserId       = currentUser.Id;
                newComment.PostId       = Convert.ToInt32(e.CommandArgument);
                newComment.comment_date = DateTime.Now;
                newComment.comment_text = comment.Text;
                CommentDAO.AddComment(newComment);
                comment.Text = String.Empty;

                repeater.DataSource = CommentDAO.GetCommentByPost(Convert.ToInt32(e.CommandArgument));
                repeater.DataBind();
            }
            if (e.CommandName == "Report")
            {
                RadioButtonList report           = (e.Item.FindControl("RadioButtonList1") as RadioButtonList);
                var             userpostindex    = e.Item.ItemIndex;
                var             rpt              = report.SelectedValue;
                List <UserPost> userposts        = new List <UserPost>();
                UserPost        selecteduserpost = ((List <UserPost>)rptUserPosts.DataSource)[userpostindex];
                var             newReport        = new BLL.ReportedPost();
                newReport.postId         = selecteduserpost.Post.Id;
                newReport.reason         = rpt;
                newReport.dateCreated    = DateTime.Now;
                newReport.reporterUserId = currentUser.Id;
                ReportedPostDAO.AddReport(newReport);
            }

            if (e.CommandName == "Delete")
            {
                var      deleteId         = Convert.ToInt32(e.CommandArgument);
                var      userpostindex    = e.Item.ItemIndex;
                UserPost selecteduserpost = ((List <UserPost>)rptUserPosts.DataSource)[userpostindex];



                if (currentUser.Id == selecteduserpost.User.Id)
                {
                    CommentDAO.DeleteCommentByPostId(selecteduserpost.Post.Id);
                    ReportedPostDAO.DeleteReportedPostByPostId(selecteduserpost.Post.Id);
                    PostDAO.DeletePost(deleteId);
                    refreshGv();

                    UserCircleDAO.ChangeUserCirclePoints(
                        userId: currentUser.Id,
                        circleName: selecteduserpost.Post.CircleId,
                        points: -30,
                        source: "removing a post",
                        addNotification: true
                        );
                }
            }
        }