示例#1
0
        public ActionResult AddComment(AddCommentViewModel model)
        {
            int userId = _accountService.GetUserByLogin(User.Identity.Name).UserId;

            _postService.AddComment(model.ToBllComment(userId, User.Identity.Name));
            return(RedirectToAction("LoadMoreComment", new { page = 0, id = model.PostId }));
        }
示例#2
0
 public IActionResult addComment(int id, string comment)
 {
     _postService.AddComment(id, new Models.Comment {
         PostId = id, Content = comment
     });
     return(new RedirectToActionResult("Detail", "Post", new { id = id }));
 }
示例#3
0
        public CommentViewModel AddComment(CommentViewModel viewModel)
        {
            Comment model = new Comment();

            model.UpdateComment(viewModel);
            var res = _postService.AddComment(model);

            return(Mapper.Map <CommentViewModel>(res));
        }
示例#4
0
        public IActionResult AddComment(string blogId, [FromBody] Comment comment)
        {
            var newComment = _postService.AddComment(blogId, comment);

            if (newComment == null)
            {
                return(NotFound($"No post found with id {blogId}"));
            }

            return(Ok(comment));
        }
示例#5
0
        public async Task <IActionResult> AddComment(CommentViewModel model)
        {
            SetIsAuth();
            Comment c = await postService.AddComment(Int32.Parse(Request.Cookies["user"]), model.PostId, model.Text);

            if (c != null)
            {
                return(Json(new { success = true, c.User.Avatar, c.User.Email, Date = c.Date.ToString("g"), c.Text }));
            }
            return(BadRequest());
        }
示例#6
0
 public virtual ActionResult Create(AddCommentViewModel commentViewModel)
 {
     if (ModelState.IsValid)
     {
         _postService.AddComment(commentViewModel.PostId, commentViewModel.Name, commentViewModel.Comment);
     }
     else
     {
         TempData["comment"] = ViewData.ModelState;
     }
     return(new RedirectResult(Request.Headers["Referer"]));
 }
示例#7
0
        public async Task <IActionResult> AddComment([FromBody] CommentDto comment)
        {
            try
            {
                var id = await _service.AddComment(comment);

                return(Ok(id));
            }
            catch (BussinessException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#8
0
        public async Task <IActionResult> AddComment([Bind("CommentId,Content,CreateAt,PostId")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                Post post = await _postService.GetPostById(comment.PostId);

                if (post != null)
                {
                    await _postService.AddComment(post, comment);

                    return(RedirectToAction("Index", new { newComment = true }));
                }
            }
            return(View());
        }
示例#9
0
        public virtual object AddComment(Area areaInput, PostBase postBaseInput, Comment commentInput, UserBase userBaseInput, UserBase currentUser, bool?remember, bool?subscribe)
        {
            if (site.CommentingDisabled)
            {
                return(null);
            }

            Area area = areaService.GetArea(areaInput.Name);

            if (area == null || area.CommentingDisabled)
            {
                return(null);
            }

            Post post = postService.GetPost(area, postBaseInput.Slug);

            if (post == null || post.CommentingDisabled)
            {
                return(null);
            }

            ValidationStateDictionary validationState;
            Comment newComment;

            postService.AddComment(area, post, commentInput, currentUser ?? userBaseInput, subscribe.HasValue && subscribe.Value, out validationState, out newComment);

            if (!validationState.IsValid)
            {
                ModelState.AddModelErrors(validationState);

                return(Item(areaInput, postBaseInput));
            }

            //todo: (nheskew) move into an action filter?
            if (remember != null && (bool)remember)
            {
                Response.Cookies.SetAnonymousUser(userBaseInput);
            }
            else if (currentUser == null && Request.Cookies.GetAnonymousUser() != null)
            {
                Response.Cookies.ClearAnonymousUser();
            }

            return(new RedirectResult(newComment.State != EntityState.PendingApproval ? Url.Comment(post, newComment) : Url.CommentPending(post, newComment)));
        }
 public IActionResult AddComment(int postId, string comment)
 {
     _postService.AddComment(comment, postId);
     return(ShowPost(postId));
 }
示例#11
0
 private IActionResult AddComment([FromBody] PostDTO PostDTO, string username, string text)
 {
     return(Ok(_postService.AddComment(PostDTO, username, text)));
 }
示例#12
0
 public void Post(string postId, [FromBody] Comment comment)
 {
     _service.AddComment(postId, comment);
 }
示例#13
0
 public void GivenAValidPost_WhenIAddAComment_AndTheDatabaseIsNotAvailable_ThenAnMBlogExceptionIsThrown()
 {
     _postRepository.Setup(p => p.AddComment(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())).Throws
     <Exception>();
     Assert.Throws <MBlogException>(() => _postService.AddComment(1, "name", "comment"));
 }