コード例 #1
0
        public void AddComment(AddComment Command)
        {
            var comment = new Comment(Command.Name, Command.Email, Command.Message, Command.ArticleId);

            _commentRepo.AddComment(comment);
            _commentRepo.Save();
        }
コード例 #2
0
        public ActionResult Add(PostDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
                //return RedirectToRoute("PostDetails", new { id = model.PostId, name = model.Post.GetTitleAsUrl() });
            }

            Comment comment = model.Comment;

            comment.DateAdded = DateTime.Now;
            comment.UserId    = User.Identity.GetUserId();
            try
            {
                _commentRepo.AddComment(comment);
                _commentRepo.SaveChanges();
                string commentClass = "comment-" + comment.Id;
                TempData["scrollId"] = commentClass;
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
コード例 #3
0
        public ActionResult <CommentDto> CreateComment(CreateCommentDto comment)
        {
            var commentEntity = _mapper.Map <Comment>(comment);

            commentRepo.AddComment(commentEntity);
            commentRepo.Save();

            var commentToReturn = _mapper.Map <CommentDto>(commentEntity);

            return(CreatedAtRoute("GetRealEstate",
                                  new { userName = commentToReturn.UserName }, commentToReturn));
        }