コード例 #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"));
        }