コード例 #1
0
        public async void Delete_Comment_By_Id_Throws_Given_Comment_Id_isEmpty()
        {
            ICommentService commentService = new CommentService(_mockCommentsRepository.Object, _mockPostRepository.Object);

            UpdateCommentViewModel updateCommentViewModel = new UpdateCommentViewModel();
            await Assert.ThrowsAsync <ArgumentException>(async() => await commentService.DeleteCommentAsync(Guid.Empty));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateComment([FromForm] UpdateCommentViewModel model)
        {
            var callerId = await _authHelper.GetCallerId(_caller);

            if (await _authHelper.CheckIfUserIsBanned(callerId))
            {
                return(new BadRequestObjectResult(
                           new
                {
                    Message = "User currently bannend",
                    StatusCodes.Status403Forbidden
                }));
            }
            var updateCommentObj = new UpdateComment(model.Id, model.Comment, callerId);
            var updatedComment   = await _commentRepository.UpdateComment(updateCommentObj);

            if (updatedComment.Files != null && updatedComment.Files.Any())
            {
                _uploadHelper.DeleteCommentFiles(updatedComment.Files);
                updatedComment.Files = await _uploadHelper.UploadFiles(model.Files, model.Id);
            }
            await _commentRepository.UpdateCommentImages(updatedComment.Files, updatedComment.Id);

            return(new OkObjectResult(new
            {
                updatedComment
            }));
        }
コード例 #3
0
        public async void Update_Comment_By_Id_Throws_Given_UpdateCommentDto_isNull()
        {
            ICommentService commentService = new CommentService(_mockCommentsRepository.Object, _mockPostRepository.Object);

            //DTO is null
            UpdateCommentViewModel updateCommentViewModel = null;
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await commentService.UpdateCommentAsync(updateCommentViewModel));
        }
コード例 #4
0
        public async Task <IActionResult> ConfirmEditComment(UpdateCommentViewModel comment)
        {
            var commentDto = Mapper.Map <CommentDto>(comment);

            commentDto.User = User.CreateUserDto();
            await _commentManager.UpdateComment(commentDto);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        public async Task <Comment> Put(Guid id, [FromBody] UpdateCommentDto comment)
        {
            var updateCommentViewModel = new UpdateCommentViewModel()
            {
                CommentId = id, Text = comment.Text
            };

            return(await _commentService.UpdateCommentAsync(updateCommentViewModel));
        }
コード例 #6
0
        public IActionResult UpdateComment([FromBody] UpdateCommentViewModel updateCommentViewModel)
        {
            if (updateCommentViewModel.Id < 1)
            {
                return(BadRequest());
            }

            _commentRepository.UpdateCommentTextById(updateCommentViewModel.Id, updateCommentViewModel.CommentText);
            return(Json("Ok"));
        }
コード例 #7
0
        public async Task <IActionResult> EditComment(UpdateCommentViewModel comment)
        {
            var commentDto = await _commentManager.GetComment(comment.Id);

            if (commentDto == null)
            {
                return(NotFound());
            }
            var model = Mapper.Map <UpdateCommentViewModel>(commentDto);

            return(View(model));
        }
コード例 #8
0
        public async Task ConfirmEditComment_UpdateModel_Ok()
        {
            var model = new UpdateCommentViewModel {
                Id = 1, Text = "Test"
            };
            var user = _controller.SetupUser(1);

            await _controller.ConfirmEditComment(model);

            _commentManager.Verify(repo => repo.UpdateComment(It.Is <CommentDto>(com =>
                                                                                 com.Text == "Test" && com.Id == 1 && com.User.Id == user.Id)), Times.Once);
        }
コード例 #9
0
        public JsonResult UpdateComment(UpdateCommentViewModel m)
        {
            try
            {
                var ci = visitsSvc.GetCheckInById(m.ID);
                ci.Comment = m.Comment;

                visitsSvc.UpdateCheckIn(ci);

                return(Json(new { Success = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Error = ex.Message }));
            }
        }
コード例 #10
0
        /// <summary>
        /// Updates comment data
        /// </summary>
        /// <param name="viewModel">new comment data</param>
        /// <returns>updated comment</returns>
        public async Task <Comment> UpdateCommentAsync(UpdateCommentViewModel viewModel)
        {
            Guard.Against.Null(viewModel, nameof(viewModel));
            Guard.Against.GuidEmpty(viewModel.CommentId, nameof(viewModel.CommentId));

            //Check Comment exists
            var comment = await _commentRepository.GetByIdAsync(viewModel.CommentId);

            Guard.Against.CommentNotExists(comment, viewModel.CommentId);

            comment.Content.Text = viewModel.Text;

            await _commentRepository.UpdateAsync(comment);

            return(await _commentRepository.GetByIdAsync(viewModel.CommentId));
        }
コード例 #11
0
        public async void Update_Comment_By_Id_Create_Post_Returns_Right_Comment()
        {
            UpdateCommentViewModel updateCommentViewModel = new UpdateCommentViewModel()
            {
                Text = "New comment text content"
            };
            Post post = new Post(new Content("Post text content"), new Title("Post title"), Guid.NewGuid());

            Comment shouldBeComment = new Comment(Guid.NewGuid(), post.Id, new Content(updateCommentViewModel.Text));

            _mockPostRepository.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(post);
            _mockCommentsRepository.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(shouldBeComment);
            _mockCommentsRepository.Setup(repo =>
                                          repo.UpdateAsync(It.IsAny <Comment>()))
            .Returns(Task.CompletedTask);

            ICommentService commentService = new CommentService(_mockCommentsRepository.Object, _mockPostRepository.Object);

            updateCommentViewModel.CommentId = shouldBeComment.Id;
            var updatedComment = await commentService.UpdateCommentAsync(updateCommentViewModel);

            Assert.Equal(updatedComment.Content.Text, shouldBeComment.Content.Text);
            Assert.Equal(updatedComment.Id, shouldBeComment.Id);
        }
コード例 #12
0
        public async Task <IActionResult> UpdateCommentAsync(string idComment, UpdateCommentViewModel updateCommentViewModel)
        {
            try
            {
                updateCommentViewModel.IdComment = idComment;

                var updateCommentRequest = updateCommentViewModel.ToBuiderCommentRequest(updateCommentViewModel);

                commentDto = await _commentService.UpdateCommentAsync(updateCommentRequest);

                if (commentDto is null)
                {
                    return(BadRequest("The Id " + idComment + " Doesn't exist."));
                }
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }

            commentDto.IdComment = idComment.ToInt().Value;

            return(Ok(commentDto));
        }