コード例 #1
0
        public async Task <IActionResult> AddComment(ActionApiModel model)
        {
            model.Comment.Created = DateTime.Now;
            var count = await _blogService.AddComment(model.BlogId, model.Comment);

            return(Ok(count));
        }
コード例 #2
0
        public async Task AddCommentTest()
        {
            var comment = new AddCommentRequest(0, "mikke", "Ei vttu, et o tosissas?!");

            await _service.AddComment(comment);

            Assert.AreEqual(1, _blog.Comments.Count);
        }
コード例 #3
0
        public async Task <ActionResult> AddComment(AddCommentViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Don't be daft, fill in the comment");
            }

            var user    = User?.Identity?.Name;
            var request = new AddCommentRequest(vm.Id, user, vm.Comment);

            await _blogService.AddComment(request);

            var model = new CommentViewModel(user, DateTime.Now, vm.Comment);

            return(PartialView(model));
        }
コード例 #4
0
ファイル: BlogController.cs プロジェクト: wu2on/Blog
        public async Task <ActionResult> AddComment(string postId, string comment, string url)
        {
            if (ModelState.IsValid)
            {
                var currentUser = User.Identity;

                CommentDto commentDto = new CommentDto
                {
                    Text          = comment,
                    CreateAt      = DateTime.Now,
                    UserProfileId = currentUser.GetUserId(),
                    UserEmail     = currentUser.Name,
                    PostId        = Int32.Parse(postId),
                    IsDeleted     = false
                };

                await BlogService.AddComment(commentDto);
            }

            return(Redirect(url));
        }
コード例 #5
0
 public async Task AddComment([FromBody] AddCommentRequest request)
 {
     await _blogService.AddComment(request);
 }