public async Task <IActionResult> UpdateAsync([FromRoute] Guid commentId,
                                                      [FromBody] UpdateCommentRequest request)
        {
            var userOwnsPost =
                await _commentService.UserOwnsCommentAsync(commentId.ToString(), HttpContext.GetUserId());

            if (!userOwnsPost)
            {
                return(BadRequest(new { error = "You do not own this comment" }));
            }

            var comment = await _commentService.GetCommentByIdAsync(commentId);

            if (comment == null)
            {
                return(NotFound());
            }

            comment.CommentText = request.CommentText;
            comment.UpdatedAt   = DateTime.UtcNow;
            var updated = await _commentService.UpdateCommentAsync(commentId);

            if (!updated)
            {
                return(NotFound());
            }
            var response = _mapper.Map <CommentResponse>(comment);

            return(Ok(new Response <CommentResponse>(response)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateComment(int commentId, UpdateCommentRequest updatedComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var comment = await commentService.UpdateCommentAsync(commentId, updatedComment);

                if (comment == null)
                {
                    return(NotFound());
                }

                return(NoContent());
            }
            catch (ResourceHasConflictException ex)
            {
                return(Conflict(ex.Message));
            }
            catch (ResourceNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
        }
        public async Task <CommentModel> UpdateCommentAsync(string commentId, UpdateCommentRequest commentRequest)
        {
            var result = blogCurrent.Commets;

            if (commentRequest.Text.Length >= 200)
            {
                throw new RequestException("Comment has length  more 200 symbols.");
            }

            var currentCommnet = result.Where(c => c.Id == commentId).FirstOrDefault();

            int index = blogCurrent.Commets.IndexOf(currentCommnet);

            if (index < 0)
            {
                throw new NotFoundException($"Not found comment.");
            }

            var comment = _mapper.Map <UpdateCommentRequest, CommentModel>(commentRequest);

            comment.Id        = commentId;
            comment.CreatedOn = currentCommnet.CreatedOn;
            comment.UpdatedOn = DateTime.Now;

            result.RemoveAt(index);
            result.Insert(index, comment);

            await _blogresitory.Update(blogCurrent.Id, blogCurrent);

            return(comment);
        }
        public async Task <IActionResult> Update([FromRoute] Guid commentId, [FromBody] UpdateCommentRequest updateRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var isUserOwnerOfComment = await _commentsRepository.IsUserOwnerOfCommentAsync(commentId, HttpContext.GetUserId());

            if (!isUserOwnerOfComment)
            {
                return(BadRequest(new { error = $"User can not update comment {commentId}" }));
            }

            var comment = await _commentsRepository.GetCommentByIdAsync(commentId);

            var updated = await _commentsRepository.UpdateCommentAsync(_mapper.Map(updateRequest, comment));

            if (updated)
            {
                return(Ok(_mapper.Map <CommentResponse>(comment)));
            }

            return(NotFound());
        }
Ejemplo n.º 5
0
 public override Task <Reply> UpdateComment(UpdateCommentRequest request, ServerCallContext context)
 {
     return(UpdateFields(request.Id, context, user =>
     {
         user.Comment = request.Comment;
         return Task.FromResult(Error.None);
     }));
 }
Ejemplo n.º 6
0
        private Comment BuilderUpdateComment(Comment comment, UpdateCommentRequest updateComment)
        {
            comment.Title       = updateComment.Title;
            comment.Description = updateComment.Description;
            comment.Creation    = DateTime.UtcNow;

            return(comment);
        }
Ejemplo n.º 7
0
        public void UpdateAComment(UpdateCommentRequest request)
        {
            request.Validate <UpdateCommentRequestValidator, UpdateCommentRequest>();
            var comment = _commentRepository.GetComment(request.Id, request.PostId);

            comment.Update(request.FirstName, request.LastName, request.Message);
            _commentRepository.Update(comment);
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <FeedViewModel> > UpdateCommentAsync(
            [FromBody] UpdateCommentRequest request,
            [FromRoute] int id)
        {
            var result = await _commentService.UpdateAsync(request, id);

            return(Ok(result));
        }
Ejemplo n.º 9
0
 public override async Task <Reply> UpdateComment(UpdateCommentRequest request, ServerCallContext context)
 {
     return(await UpdateFields(request.Id, context, item =>
     {
         item.Comment = request.Comment;
         return Task.FromResult(Error.None);
     }));
 }
Ejemplo n.º 10
0
        public object Any(UpdateCommentRequest request)
        {
            var repo = new PostRepository().UpdateCommentOfAlbumOrImage(request.CommentId, request.CommentContent, request.ApiKey);

            AutoMapper.Mapper.CreateMap<PostEditResponseModel, PostEditResponse>();

            return AutoMapper.Mapper.Map<PostEditResponse>(repo);

        }
Ejemplo n.º 11
0
        public void Put(string id, UpdateCommentRequest body)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    body != null &&
                                    !string.IsNullOrEmpty(body.ClassRoomId) &&
                                    !string.IsNullOrEmpty(body.LessonId) &&
                                    !string.IsNullOrEmpty(body.UserProfileId);

            if (!areArgumentsValid)
            {
                return;
            }

            var canAccessToTheClassRoom = _userprofileRepo.CheckAccessPermissionToSelectedClassRoom(body.UserProfileId, body.ClassRoomId);

            if (!canAccessToTheClassRoom)
            {
                return;
            }

            var now = _dateTime.GetCurrentTime();
            var canAccessToTheClassLesson = _classCalendarRepo.CheckAccessPermissionToSelectedClassLesson(body.ClassRoomId, body.LessonId, now);

            if (!canAccessToTheClassLesson)
            {
                return;
            }

            var selectedComment = _commentRepo.GetCommentById(id);

            if (selectedComment == null)
            {
                return;
            }

            var isCommentOwner = selectedComment.CreatedByUserProfileId.Equals(body.UserProfileId, StringComparison.CurrentCultureIgnoreCase);

            if (!isCommentOwner)
            {
                return;
            }

            if (body.IsDelete)
            {
                selectedComment.DeletedDate = now;
            }
            else
            {
                if (string.IsNullOrEmpty(body.Description))
                {
                    return;
                }
                selectedComment.Description = body.Description;
            }
            _commentRepo.UpsertComment(selectedComment);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> UpdateComment(UpdateCommentRequest request)
        {
            var response = await mediator.Send(request);

            logger.LogResponse(
                $"User #{HttpContext.GetCurrentUserId()} updated comment #{request.CommentId} in post #{request.PostId}",
                response.Error);

            return(this.CreateResponse(response));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Update([FromBody] UpdateCommentRequest updateCommentRequest)
        {
            if (ModelState.IsValid)
            {
                Response result = await _commentService.UpdateComment(updateCommentRequest);

                return(Ok(result));
            }
            Response response = new Response();

            return(BadRequest(response.GetResponse("Modelo no valido", 0, false)));
        }
Ejemplo n.º 14
0
        public async Task UpdateComment(UpdateCommentRequest request)
        {
            var response = await this.requestPipelineMediator.Handle <UpdateCommentRequest, OperationResult <UpdateCommentResponse> >(request);

            if (response.Succeded)
            {
                await this.Clients.Caller.SendAsync("CommentUpdated", response.Value);

                response.Value.Comment.IsOwner = false;
                await this.Clients.OthersInGroup(request.RetroId.ToString())
                .SendAsync("CommentUpdated", response.Value);
            }
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> PutOnQuestionAsync(
            [FromRoute] Guid questionId,
            [FromRoute] Guid commentId,
            [FromBody] UpdateCommentRequest request)
        {
            var comment = _mapper.Map <CommentEditModel>(request);

            comment.ParentQuestionId = questionId;
            comment.UserId           = User.UserId().Value;
            comment.CommentId        = commentId;
            await _commentService.EditAsync(comment);

            return(NoContent());
        }
Ejemplo n.º 16
0
        //Update
        public async Task <CommentResponse> UpdateComment(int id, UpdateCommentRequest model)
        {
            var comment = await GetComment(id);

            if (comment == null)
            {
                throw new AppException("Update comment failed");
            }
            //comment.Content = model.Content;
            _mapper.Map(model, comment);
            _context.Comments.Update(comment);
            await _context.SaveChangesAsync();

            return(_mapper.Map <CommentResponse>(comment));;
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Update([FromBody] UpdateCommentRequest request)
        {
            var existingComment = await this.postService.GetAsync(request.Id);

            if (existingComment == null)
            {
                return(new BadRequestResult());
            }

            existingComment.Content = request.Content;

            await this.postService.UpdateAsync(existingComment);

            return(new OkResult());
        }
        public async Task <IActionResult> Update(string id, [FromBody] UpdateCommentRequest updateComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = HttpContext.User.Claims.First().Value;

            updateComment.UserId = userId;

            await _commentsService.UpdateCommentAsync(id, updateComment);

            return(NoContent());
        }
Ejemplo n.º 19
0
        public LacesResponse UpdateComment(UpdateCommentRequest request)
        {
            LacesResponse response = new LacesResponse();

            try
            {
                if (request.SecurityString == ConfigurationManager.AppSettings[Constants.APP_SETTING_SECURITY_TOKEN])
                {
                    Comment comment = new Comment(request.CommentId);

                    comment.Text        = request.Text;
                    comment.UpdatedDate = DateTime.Now;

                    if (comment.Update())
                    {
                        response.Success = true;
                        response.Message = "Comment updated succesfully.";
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "An error occurred when communicating with the database.";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "Invalid security token.";
                }
            }
            catch (Exception ex)
            {
                response         = new LacesResponse();
                response.Success = false;

                if (ex.Message.Contains("find comment"))
                {
                    response.Message = ex.Message;
                }
                else
                {
                    response.Message = "An unexpected error has occurred; please verify the format of your request.";
                }
            }

            return(response);
        }
        public async Task <IActionResult> Create([FromBody] UpdateCommentRequest updateComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string userId = HttpContext.User.Claims.First().Value;

            updateComment.UserId = userId;

            Comment comment = await _commentsService.AddCommentAsync(updateComment);

            string location = $"api/[controller]/{comment.Id}";

            return(Created(location, comment));
        }
Ejemplo n.º 21
0
        public async Task <CommentDto> UpdateCommentAsync(UpdateCommentRequest updateComment)
        {
            var commentEntity = await _commentQuery.GetCommentByIdAsync(updateComment.IdComment.ToInt().Value);

            if (commentEntity is null)
            {
                return(null);
            }

            var commentUpdate = BuilderUpdateComment(commentEntity, updateComment);

            await _commentRepository.UpdateCommentAsync(commentUpdate);

            var commentDto = CommentDto.BuilderCommentDto(commentUpdate);

            return(commentDto);
        }
Ejemplo n.º 22
0
 public override Task <UpdateCommentResponse> UpdateComment(UpdateCommentRequest request, ServerCallContext context)
 {
     try
     {
         PostComment.Comment comment = new PostComment.Comment();
         var returnValue             = comment.UpdateComment((global::PostComment.Comment)request.NewComment);
         var response = new UpdateCommentResponse {
             Value = (Comment)returnValue
         };
         return(Task.FromResult(response));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error invoking UpdateComment");
         throw new RpcException(new Status(StatusCode.Internal, ex.Message));
     }
 }
Ejemplo n.º 23
0
        public void TestUpdateComment()
        {
            string remoteFileName = "TestUpdateComment.docx";

            this.UploadFileToStorage(
                remoteDataFolder + "/" + remoteFileName,
                null,
                null,
                File.ReadAllBytes(LocalTestDataFolder + localFile)
                );

            var request = new UpdateCommentRequest(
                name: remoteFileName,
                commentIndex: 0,
                comment: new CommentUpdate()
            {
                RangeStart = new DocumentPosition()
                {
                    Node = new NodeLink()
                    {
                        NodeId = "0.3.0"
                    },
                    Offset = 0
                },
                RangeEnd = new DocumentPosition()
                {
                    Node = new NodeLink()
                    {
                        NodeId = "0.3.0"
                    },
                    Offset = 0
                },
                Initial = "IA",
                Author  = "Imran Anwar",
                Text    = "A new Comment"
            },
                folder: remoteDataFolder
                );
            var actual = this.WordsApi.UpdateComment(request);

            Assert.NotNull(actual.Comment);
            Assert.AreEqual("A new Comment" + "\r\n", actual.Comment.Text);
            Assert.NotNull(actual.Comment.RangeStart);
            Assert.NotNull(actual.Comment.RangeStart.Node);
            Assert.AreEqual("0.3.0.1", actual.Comment.RangeStart.Node.NodeId);
        }
Ejemplo n.º 24
0
        public void WhenUserProfileIdRemoveTheCommentInTheLessonOfClassRoom(string userprofileName, string commentId, string lessonId, string classRoomId)
        {
            var mockCommentRepo = ScenarioContext.Current.Get <Mock <ICommentRepository> >();

            mockCommentRepo.Setup(it => it.UpsertComment(It.IsAny <Comment>()));

            var commentCtrl = ScenarioContext.Current.Get <CommentController>();
            var body        = new UpdateCommentRequest
            {
                ClassRoomId   = classRoomId,
                LessonId      = lessonId,
                UserProfileId = userprofileName,
                IsDelete      = true
            };

            commentCtrl.Put(commentId, body);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> EditAsync([FromRoute] int id, [FromBody] UpdateCommentRequest request)
        {
            var originComment = await _commentService.GetCommentAsync(id);

            if (!originComment.UserId.Equals(request.UserId))
            {
                return(NotFound());
            }
            request.CreatedAt = DateTime.Now;
            var updatedComment = _mapper.Map(request, originComment);
            await _commentService.UpdateAsync(updatedComment).ConfigureAwait(false);

            var comment = await _commentService.GetCommentAsync(id);

            var mappedComment = _mapper.Map <CommentResponse>(comment);

            return(Ok(mappedComment));
        }
Ejemplo n.º 26
0
        public async Task UpdateComment(UpdateCommentRequest request, CancellationToken cancellationToken)
        {
            var comment = await _repository.FindById(request.Id, cancellationToken);

            if (comment == null)
            {
                throw new NotFoundCommentException(request.Id);
            }

            var user = await _identityService.GetCurrentIdentityUserId(cancellationToken);

            if (user.Id != comment.AuthorId.ToString())
            {
                throw new NoUserForCommentCreationException("Нет прав для редактирования комментария.");
            }


            await _repository.Save(_mapper.Map(request, comment), cancellationToken);
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Update(int id, [FromBody] UpdateCommentRequest commentRequest)
        {
            Comment comment = _commentRepository.Find(id);
            bool    admin   = HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == "Admin").Value == "True";
            int     userId  = int.Parse(HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == "Id").Value);

            if (comment != null && (comment.UserId == userId || admin))
            {
                comment.Body = commentRequest.Body;
                _commentRepository.Update(comment);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            else
            {
                return(Unauthorized());
            }
        }
Ejemplo n.º 28
0
        public override Task <UpdateCommentResponse> UpdateComment(UpdateCommentRequest request, ServerCallContext context)
        {
            UpdateCommentResponse output = new UpdateCommentResponse();

            Comment oldComment = _context.Comments.Find(request.Id);

            if (request.Text != null)
            {
                oldComment.Text = request.Text;
            }
            if ((oldComment.PostPostId != request.Postid) && (request.Postid != 0))
            {
                oldComment.PostPostId = request.Postid;
            }
            _context.SaveChanges();
            output.Id = oldComment.CommentId;

            return(Task.FromResult(output));
        }
Ejemplo n.º 29
0
 public IActionResult UpdateComment([FromBody] UpdateCommentRequest request)
 {
     try
     {
         var comment = _commentRepository.GetById(request.CommentId);
         if (comment == null)
         {
             return(BadRequest(new ErrorViewModel
             {
                 ErrorCode = "400",
                 ErrorMessage = "Comment not found"
             }));
         }
         if (comment.UserId != request.UserId)
         {
             return(BadRequest(new ErrorViewModel
             {
                 ErrorCode = "400",
                 ErrorMessage = "User can't change this comment"
             }));
         }
         comment.Context = request.Context;
         var response = _commentServices.UpdateComment(comment);
         if (response != "OK")
         {
             return(BadRequest(new ErrorViewModel
             {
                 ErrorCode = "400",
                 ErrorMessage = "Can not execute. Plz contact admin"
             }));
         }
         return(Ok(comment));
     }
     catch (Exception e)
     {
         return(BadRequest(new ErrorViewModel
         {
             ErrorCode = "400",
             ErrorMessage = $"Server Error: {e.Message}"
         }));
     }
 }
Ejemplo n.º 30
0
        public async Task <CommentModel> CreateCommentAsync(UpdateCommentRequest commentRequest)
        {
            if (commentRequest.Text.Length >= 200)
            {
                throw new RequestException("Comment has length  more 200 symbols.");
            }

            var comment     = _mapper.Map <UpdateCommentRequest, CommentModel>(commentRequest);
            var dateTimeNow = DateTime.Now;

            comment.CreatedOn = dateTimeNow;
            comment.UpdatedOn = dateTimeNow;

            comment.Id = RenerateStringID();
            blogCurrent.Commets.Add(comment);

            await _blogresitory.Update(blogCurrent.Id, blogCurrent);

            return(comment);
        }
Ejemplo n.º 31
0
        public async Task <ActionResult <UpdateCommentRequest> > AddComment(UpdateCommentRequest createdComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var comment = await commentService.CreateCommentAsync(createdComment);

                return(CreatedAtAction("GetComment", new { commentId = comment }, comment));
            }
            catch (ResourceHasConflictException ex)
            {
                return(Conflict(ex.Message));
            }
            catch (ResourceNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
        }