public ActionResult AddComment(Comment comment) { CommentDAO dao = new CommentDAO(); if (string.IsNullOrEmpty(comment.Name)) { ModelState.AddModelError("Name", "Нет вашего имени!"); } if (string.IsNullOrEmpty(comment.Email)) { ModelState.AddModelError("Email", "Нет вашего email!"); } if (string.IsNullOrEmpty(comment.Body)) { ModelState.AddModelError("Body", "Нет вашего сообщения!"); } if (ModelState.IsValid) { Comment newComment = new Comment() { Name = comment.Name, Body = comment.Body, Email = comment.Email, Date = DateTime.Now.Date }; dao.AddComment(newComment); return(RedirectToAction("AddComment")); } else { var listComment = dao.GetListComment(); return(View(listComment)); } }
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 ); } } }
public async Task <ActionResult> Comment(Comment data) { CommentDAO cmtDao = new CommentDAO(); cmtDao.AddComment(data); var options = new PusherOptions(); options.Cluster = "ap1"; var pusher = new Pusher("1072058", "b50b10f861de3e38c121", "50c05543df2a7eab8101", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public void GetCommentsByMovieTest() { Comment comment = new Comment(); comment.Text = "Very nice."; comment.Date = DateTime.Now; comment.MovieId = 5; comment.ClientId = 10; CommentDAO commentDAO = new CommentDAO(); commentDAO.AddComment(comment); List <string> expected = new List <string>(); expected.Add(ToStringWithoutId(comment)); comment = new Comment(); comment.Text = "It's the worst movie I've ever seen."; comment.Date = DateTime.Now; comment.MovieId = 5; comment.ClientId = 7; commentDAO.AddComment(comment); expected.Add(ToStringWithoutId(comment)); List <Comment> list = commentDAO.GetCommentsByMovie((int)comment.MovieId); if (list == null || list.Count < 2) { Assert.Fail(); } List <string> actual = new List <string>(); for (int i = list.Count - 2; i < list.Count; i++) { actual.Add(ToStringWithoutId(list[i])); } CollectionAssert.AreEqual(expected, actual); }
public void DeleteCommentTest() { Comment comment = new Comment(); comment.Text = "Very nice."; comment.Date = DateTime.Now; comment.MovieId = 5; comment.ClientId = 10; CommentDAO commentDAO = new CommentDAO(); commentDAO.AddComment(comment); List <Comment> list = commentDAO.GetCommentsByMovie((int)comment.MovieId); comment = list[list.Count - 1]; commentDAO.DeleteComment(comment.Id); list = commentDAO.GetCommentsByMovie((int)comment.MovieId); Assert.IsFalse(list.Exists(l => l.Id == comment.Id)); }
public void AddCommentTest() { Comment comment = new Comment(); comment.Text = "Very nice."; comment.Date = DateTime.Now; comment.MovieId = 5; comment.ClientId = 10; CommentDAO commentDAO = new CommentDAO(); commentDAO.AddComment(comment); List <Comment> list = commentDAO.GetCommentsByMovie((int)comment.MovieId); if (list == null || list.Count == 0) { Assert.Fail(); } string expected = ToStringWithoutId(comment); string actual = ToStringWithoutId(list[list.Count - 1]); Assert.AreEqual(expected, actual); }
public ActionResult AddComment(ViewCommentPO view, string ratingDropdown) { ActionResult response = null; //Only registered users can submit comments. if (ModelState.IsValid && Session["UserID"] != null && (int)Session["UserRole"] <= 3) { try { //Parse the rating given to a byte, and set the date/time of submit. view.Comment.Rating = byte.Parse(ratingDropdown); view.Comment.CommentTime = DateTime.Now; //Add the comment to the database and refresh the page. CommentDO commentObject = Mapper.CommentPOtoDO(view.Comment); _dataAccess.AddComment(commentObject); response = RedirectToAction("ViewGameComments", "Comments", new { specificGame = view.Comment.GameID }); } catch (Exception ex) { Logger.Log(ex); response = RedirectToAction("Index", "Games"); } finally { } } //If adding the comment failed, give them back their comment at that game. else { view.CommentList = ObtainGameComments(view.Comment.GameID); FillTempData(view.Comment.GameID); if (Session["UserID"] != null) { view.Comment.UserID = (int)Session["UserID"]; } response = View("ViewGameComments", view); } return(response); }