public async Task Update_NotFound()
        {
            // Setup
            const string commentId = "someId";
            var          model     = new UpdateCommentModel
            {
                Content = "New Content"
            };

            DomainResult domainResult = DomainResult.Success();

            var serviceMock = new Mock <ICommentsService>();

            serviceMock.Setup(s => s.UpdateAsync(commentId, model.Content)).ReturnsAsync(domainResult);
            serviceMock.Setup(s => s.GetByIdAsync(commentId)).ReturnsAsync(default(Comment));

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"comments/{commentId}", model.AsJsonContent());

            Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound);
        }
Exemple #2
0
        public async Task CommentForGasStation_UpdateContent_UpdatedContentCanBeRetrieved()
        {
            // given

            var gasStationId = await CreateGasStation();

            var addCommentModel = new AddCommentModel
            {
                Content   = "Comment",
                SubjectId = gasStationId.ToString(),
                Tag       = CommentTag.GasStation
            };

            var createdAt = await fixture.HttpClient.PostJsonAsync <CreatedResponse>(Routes.Comments.ToString(), addCommentModel);

            // when

            var updateCommentModel = new UpdateCommentModel {
                Content = "Updated Comment"
            };
            await fixture.HttpClient.PutJsonAsync($"{ Routes.Comments }/{ createdAt.Id }", updateCommentModel);

            // then

            var comment = await fixture.HttpClient.GetJsonAsync <Comment>($"{ Routes.Comments }/{ createdAt.Id }");

            comment.Should().BeEquivalentTo(updateCommentModel);
        }
Exemple #3
0
        public async Task Update(long id, UpdateCommentModel model)
        {
            var comment = await dbContext.Comments.GetAsync(id);

            comment.Update(model);
            await dbContext.SaveChangesAsync();
        }
        public void UpdateComment(UpdateCommentModel model)
        {
            var entity = MapperService.Instance.Map <UpdateCommentModel, Comment>(model);

            uow.CommentRepository.Update(entity);

            uow.Commit();
        }
Exemple #5
0
        public async Task UpdateCommentAsync(UpdateCommentModel model)
        {
            ArgumentGuard.NotNull(model, nameof(model));
            ArgumentGuard.NotEmpty(model.Id, nameof(model.Id));

            // permissions

            await _commentService.UpdateCommentAsync(model);
        }
        public async Task UpdateAsync(Guid commentId, SaveCommentModel saveCommentModel)
        {
            var updateCommentModel = new UpdateCommentModel
            {
                Id      = commentId,
                Content = saveCommentModel.Content
            };

            await _commentManager.UpdateCommentAsync(updateCommentModel);
        }
Exemple #7
0
        private bool UpdateCommentEntity(CommentEntity commentEntity, UpdateCommentModel updateCommentModel)
        {
            var requireUpdate = false;

            if (commentEntity.Content != updateCommentModel.Content)
            {
                commentEntity.Content = updateCommentModel.Content;
                requireUpdate         = true;
            }

            return(requireUpdate);
        }
Exemple #8
0
        public void ShouldThrowArgumentNullExceptionWhenUpdateWithEmptyModel()
        {
            UpdateCommentModel model = null;

            var exception =
                Record.Exception(
                    () => TestedService.Update(model)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public BaseServiceResult Update([FromBody] UpdateCommentModel updateCommentModel)
        {
            try
            {
                CommentService.Update(updateCommentModel);

                return(BaseServiceResult.Success());
            }
            catch (Exception e)
            {
                Logger?.LogError(e, $"Trying to: Update comment \"{updateCommentModel?.Id}\".");
                return(BaseServiceResult.Error(e));
            }
        }
        public Task <Result <CommentCoreModel> > Edit(UpdateCommentModel model)
        => Result <CommentCoreModel> .TryAsync(async() =>
        {
            var comment = (await _repository.FirstOrDefaultAsync <Comment>(i => i.Id == model.Id)).Data;
            if (comment == null)
            {
                return(Result <CommentCoreModel> .Failed(Error.WithData(1000, new[] { "Comment Not Found" })));
            }

            comment.Text   = model.Text;
            comment.BlobId = model.BlobId;
            comment.BlobId = model.BlobId;

            await _repository.CommitAsync();
            return(Result <CommentCoreModel> .Successful(_autoMapper.Map <CommentCoreModel>(comment)));
        });
        public bool AddNewCommentForPost(int currentUserId, UpdateCommentModel comment)
        {
            var isPostAvailable = this.context.Post.Any(x => x.Id == comment.PostId);

            if (!isPostAvailable)
            {
                return(isPostAvailable);
            }

            this.context.PostComment.Add(new PostComment()
            {
                CommentContent    = comment.Content,
                CommentedByUserId = currentUserId,
                CommentedOn       = CommonUtilities.GetCurrentDateTime(),
                PostId            = comment.PostId,
            });

            return(this.context.SaveChanges() > 0);
        }
Exemple #12
0
        public async Task <IActionResult> Update(UpdateCommentModel model)
        {
            if (!Guid.TryParse(CurrentUser.NameIdentifier, out Guid userId))
            {
                return(Json(new { Status = false, Message = "Error updating comment." }));
            }

            model.UserId = userId;

            var validationResult = UpdateCommentModelValidator.Validate(model);

            if (!validationResult.IsValid)
            {
                return(Json(new { status = validationResult.IsValid, Messages = validationResult.Messages }));
            }

            var result = CommentService.Update(model);

            return(null);
        }
Exemple #13
0
        public async Task UpdateCommentAsync(UpdateCommentModel model)
        {
            ArgumentGuard.NotNull(model, nameof(model));
            ArgumentGuard.NotEmpty(model.Id, nameof(model.Id));

            // validate

            var commentEntity = await _commentRepository.GetAsync(model.Id);

            var shouldUpdate = UpdateCommentEntity(commentEntity, model);

            if (!shouldUpdate)
            {
                return;
            }

            commentEntity.LastModfiedById     = _userContext.UserId;
            commentEntity.LastModifiedDateUtc = DateTime.UtcNow;

            await _commentRepository.UpdateAsync(commentEntity);
        }
Exemple #14
0
        public IActionResult AddNewCommentForPost([FromBody] UpdateCommentModel comment)
        {
            try
            {
                var postId             = string.IsNullOrWhiteSpace(comment.PostHashId) ? 0 : Convert.ToInt32(comment.PostHashId.ToDecrypt());
                var currentUserDetails = this.userResolverService.GetLoggedInUserDetails();
                if (currentUserDetails.UserId == 0 || postId == 0 || string.IsNullOrWhiteSpace(comment.Content))
                {
                    return(BadRequest());
                }

                var response = this.postService.AddNewCommentForPost(currentUserDetails.UserId, comment);

                return(Ok(response));
            }
            catch (System.Exception ex)
            {
                this.logger.LogError(ex, "Error occurred in Get PostComments By Post Hash Id.");
                return(BadRequest(new { message = "Something went wrong, Please Try again Later." }));
            }
        }
        /// <summary>
        /// Update specified comment by values
        /// </summary>
        /// <param name="updateCommentModel">Comment new values</param>
        /// <exception cref="ArgumentNullException">Parameter updateCommentModel is null</exception>
        /// <exception cref="ArgumentNullException">Message isn't specified</exception>
        /// <exception cref="ArgumentNullException">Parameter commentId is default</exception>
        /// <exception cref="EntityNotFoundException">Comment not found</exception>
        public void Update(UpdateCommentModel updateCommentModel)
        {
            if (updateCommentModel == null)
            {
                throw new ArgumentNullException(nameof(updateCommentModel));
            }
            if (string.IsNullOrEmpty(updateCommentModel.Message))
            {
                throw new ArgumentNullException(nameof(updateCommentModel.Message));
            }

            GetCommentWithWithChecking(updateCommentModel.Id);

            var newValues = new ExpandoObject();

            newValues.TryAdd(nameof(Comment.Message), updateCommentModel.Message);

            if (!string.IsNullOrEmpty(updateCommentModel.Description))
            {
                newValues.TryAdd(nameof(Comment.Description), updateCommentModel.Description);
            }

            CommentsDataProvider.Update(updateCommentModel.Id, newValues);
        }
Exemple #16
0
        public async Task Update_BadRequest_EmptyContent()
        {
            // Setup
            const string commentId = "someId";
            var          model     = new UpdateCommentModel();

            DomainResult domainResult = DomainResult.Success();

            Comment comment = new Comment(commentId, model.Content, DateTimeOffset.Now, null, null, null);

            var serviceMock = new Mock <ICommentsService>();

            serviceMock.Setup(s => s.UpdateAsync(commentId, model.Content)).ReturnsAsync(domainResult);

            var client = TestServerHelper.New(collection =>
            {
                collection.AddScoped(_ => serviceMock.Object);
            });

            // Act
            var response = await client.PutAsync($"comments/{commentId}", model.AsJsonContent());

            Assert.AreEqual(response.StatusCode, HttpStatusCode.BadRequest);
        }
Exemple #17
0
 public async Task <CommentViewModel> Update(UpdateCommentModel model)
 {
     return(new CommentViewModel());
 }
Exemple #18
0
 internal void Update(UpdateCommentModel model)
 {
     Content   = model.Content;
     WasEdited = true;
 }
Exemple #19
0
        public async Task <IActionResult> Update(long id, [FromBody] UpdateCommentModel model)
        {
            await service.Update(id, model);

            return(NoContent());
        }
Exemple #20
0
        public async Task <ActionResult <Comment> > UpdateAsync([FromRoute] string commentId, [FromBody][Required] UpdateCommentModel model)
        {
            if (await commentService.GetByIdAsync(commentId) == null)
            {
                return(NotFound());
            }

            var domainResult = await commentService.UpdateAsync(commentId, model.Content);

            if (!domainResult.Successed)
            {
                return(BadRequest(domainResult.ToProblemDetails()));
            }

            return(NoContent());
        }
Exemple #21
0
 public CommentModel UpdateComment([FromBody] UpdateCommentModel model)
 {
     return(_commentService.UpdateComment(model, GetUserId()));
 }
Exemple #22
0
 public async Task <Result <CommentCoreModel> > Edit(UpdateCommentModel model)
 => await _commentBiz.Edit(model);