コード例 #1
0
        public ActionResult AddComment()
        {
            string newComment;

            newComment = Request.Form["NewComment"];
            int pictureId = int.Parse(Request.Form["currentID"]);

            if (newComment == "")
            {
                return(RedirectToAction("Details/" + pictureId, "Pictures"));
            }
            int     userId  = AuthManager.GetAuthenticated().Id;
            Comment comment = new Comment()
            {
                UserId  = userId,
                Content = newComment,
                Picture = db.Pictures.Find(pictureId)
            };

            db.Comments.Add(comment);
            db.SaveChanges();

            NotificationsController.AddCommentNotification(pictureId, userId);
            return(RedirectToAction("Details/" + pictureId, "Pictures"));
        }
コード例 #2
0
        public ActionResult DeleteComment()
        {
            int deleteCommentId;

            deleteCommentId = int.Parse(Request.Form["currentCommentID"]);
            int     pictureId       = int.Parse(Request.Form["CurrentPictureID"]);
            Comment commentToDelete = db.Comments.Find(deleteCommentId);

            db.Comments.Remove(commentToDelete);
            db.SaveChanges();
            NotificationsController.RemoveCommentNotification(commentToDelete, pictureId);
            return(RedirectToAction("Details/" + pictureId, "Pictures"));
        }