コード例 #1
0
        public ActionResult PostComment(PostComment postedComment)
        {
            var laptop = db.Laptops.GetById(postedComment.LaptopId);
            var user = db.Users.All().Single(x => x.UserName == User.Identity.Name);


            Comment comment = new Comment
            {
                Content = postedComment.Content,
                Laptop = laptop,
                User = user
            };

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

            var comments = db.Comments.All("User", "Laptop")
                .Where(x => x.Laptop.Id == postedComment.LaptopId)
                .ToList().ToViewModel();

            //string renderHtml = RenderPartialViewToString("_Comments", comments);

            return PartialView("_Comments", comments);
            //return renderHtml;
        }
コード例 #2
0
        public ActionResult Comment(CommentModel model)
        {
            Comment comment = new Comment()
            {
                AuthorId = User.Identity.GetUserId(),
                LaptopId = model.LaptopId,
                Content = model.Content
            };

            this.Db.CommentsRepository.Add(comment);
            this.Db.SaveChanges();

            var commentViewModel = new CommentViewModel()
            {
                Author = User.Identity.Name,
                Content = comment.Content
            };

            return PartialView("_CommentPartial", commentViewModel);
        }