protected void rptUserPosts_ItemDataBound(object sender, RepeaterItemEventArgs e) { Repeater repeater = (e.Item.FindControl("rptComment") as Repeater); var data = e.Item.DataItem; DAL.UserPost userpost = data as DAL.UserPost; repeater.DataSource = CommentDAO.GetCommentByPost(userpost.Post.Id); repeater.DataBind(); var deltee = e.Item.ItemIndex; var dletepost = userpost.User.Id; Button delte = (e.Item.FindControl("Delete") as Button); HyperLink report = (e.Item.FindControl("mreport") as HyperLink); if (currentUser.Id == dletepost) { delte.Visible = true; } else { delte.Visible = false; } //if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) //{ // var post = e.Item.DataItem as DAL.Post; // repeater.DataSource = CommentDAO.GetCommentByPost(post.Id); // repeater.DataBind(); //} }
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 ); } } }