示例#1
0
        public async Task <ServiceResponse <GetCommentDto> > Update(UpdateCommentDto updateCommentDto)
        {
            ServiceResponse <GetCommentDto> response = new ServiceResponse <GetCommentDto>();
            User user = await _context.Users.FirstOrDefaultAsync(u => u.Id == GetUserId());

            Comment comment = await _context.Comments.Include(c => c.CommentedUser).FirstOrDefaultAsync(s => s.Id == updateCommentDto.CommentId);

            if (user.Id != comment.CommentedUserId)
            {
                response.Data    = null;
                response.Message = "You are not authorized to make comment";
                response.Success = false;
                return(response);
            }
            comment.CommentText = updateCommentDto.CommentText;
            comment.MaxGrade    = updateCommentDto.MaxGrade;
            comment.Grade       = updateCommentDto.Grade;
            _context.Comments.Update(comment);
            await _context.SaveChangesAsync();

            response.Data = _mapper.Map <GetCommentDto>(comment);
            response.Data.FileEndpoint = "Comment/File/" + comment.Id;
            response.Data.HasFile      = comment.FileAttachmentAvailability;
            response.Data.FileName     = comment.FileAttachmentAvailability ? comment.FilePath.Split('/').Last() : "";
            return(response);
        }
示例#2
0
        public async Task <IActionResult> PutComment(long id, UpdateCommentDto updateCommentDto)
        {
            if (id != updateCommentDto.Id)
            {
                return(BadRequest());
            }

            var commentEntity = CommentMapper.mapFromUpdateDto(updateCommentDto);

            _context.Entry(commentEntity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public async Task UpdateComment(UpdateCommentDto input)
        {
            var comment = await _commentRepository.GetByIdAsync(input.Id);

            comment.Content      = input.Content;
            comment.ModifiedDate = DateTime.Now;
            await _commentRepository.UpdateAsync(comment);
        }
示例#4
0
        private async Task <CommentDto> UpdateCommentAsync(Guid id, Comment comment, UpdateCommentDto input)
        {
            comment.SetText(input.Text);

            comment = await _commentRepository.UpdateAsync(comment);

            return(ObjectMapper.Map <Comment, CommentDto>(comment));
        }
 public virtual async Task <CommentWithDetailsDto> UpdateAsync(Guid id, UpdateCommentDto input)
 {
     return(await RequestAsync <CommentWithDetailsDto>(nameof(UpdateAsync), new ClientProxyRequestTypeValue
     {
         { typeof(Guid), id },
         { typeof(UpdateCommentDto), input }
     }));
 }
示例#6
0
        public async Task <CommentViewModel> UpdateCommentAsync(Comment comment, UpdateCommentDto updateCommentDto)
        {
            comment.Content = updateCommentDto.Content;

            await _commentRepository.UpdateAsync(comment);

            return(_mapper.Map <CommentViewModel>(comment));
        }
        public async Task <Result> Update(UpdateCommentDto updateCommentDto)
        {
            var comment = await FirstOrDefaultAsync(c => c.Id == updateCommentDto.Id);

            _mapper.Map(updateCommentDto, comment);
            await Context.SaveChangesAsync();

            return(Result.SuccessFull());
        }
示例#8
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));
        }
        public static Comment mapFromUpdateDto(UpdateCommentDto updateComment)
        {
            Comment result = new Comment();

            result.Id        = updateComment.Id;
            result.Important = updateComment.Important;
            result.Text      = updateComment.Text;
            return(result);
        }
示例#10
0
        public async Task <IActionResult> UpdateComment(UpdateCommentDto updateComment)
        {
            Comment comment = await _repository.GetComment(updateComment.Id);

            comment.Content    = updateComment.Content;
            comment.ModifiedOn = DateTime.UtcNow;

            _repository.Add(comment);
            return(Ok(await _repository.SaveAll()));
        }
示例#11
0
        public async Task <CommentDto> UpdateAsync(Guid id, UpdateCommentDto input)
        {
            var comment = await _commentRepository.GetAsync(id);

            comment.SetText(input.Text);

            comment = await _commentRepository.UpdateAsync(comment);

            return(ObjectMapper.Map <Comment, CommentDto>(comment));
        }
示例#12
0
        public int UpdateComment(int id, UpdateCommentDto updateCommentDto)
        {
            var comment = GetCommentEntity(id);

            comment.Value  = updateCommentDto.Value ?? comment.Value;
            comment.NewsId = updateCommentDto.NewsId ?? comment.NewsId;
            comment.UserId = updateCommentDto.UserId ?? comment.UserId;

            _db.SaveChanges();
            return(comment.Id);
        }
示例#13
0
        public async Task <CommentDto> UpdateAsync(Guid id, UpdateCommentDto input)
        {
            var comment = await _commentRepository.GetAsync(id);

            if (CurrentUser.Id != comment.CreatorId)
            {
                return(await UpdateAsAdminAsync(id, comment, input));
            }

            return(await UpdateCommentAsync(id, comment, input));
        }
        public async void Comments_PUT_Returns_404()
        {
            UpdateCommentDto updatedComment = new UpdateCommentDto()
            {
                Text = string.Empty
            };

            var response = await this.HttpClient.PutAsync($"/api/v1/comments/{Guid.NewGuid()}", new StringContent(JsonConvert.SerializeObject(updatedComment), Encoding.UTF8, "application/json"));

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public void Execute(UpdateCommentDto request)
        {
            var comment = Context.Comments.Find(request.Id);

            if (comment == null || comment.IsDeleted)
            {
                throw new EntityNotFoundException();
            }
            comment.Text = request.Text;
            Context.SaveChanges();
        }
        public async Task <IActionResult> Update(Guid id, [FromBody] UpdateCommentDto updateCommentDto)
        {
            updateCommentDto.Id = id;
            var result = await _unitOfWork.CommentService.Update(updateCommentDto);

            if (!result.Success)
            {
                return(result.ApiResult);
            }
            return(NoContent());
        }
示例#17
0
        public async Task <IActionResult> UpdateComment(string postId, string id, [FromBody] UpdateCommentDto updateCommentDto)
        {
            var result = await Mediator.Send(new UpdateCommentCommand
            {
                UpdateCommentDto = updateCommentDto,
                PostId           = postId,
                Id     = id,
                UserId = AuthorizedUserId
            });

            return(Ok(result));
        }
示例#18
0
        public async Task <CommentWithDetailsDto> UpdateAsync(Guid id, UpdateCommentDto input)
        {
            var comment = await _commentRepository.GetAsync(id);

            await AuthorizationService.CheckAsync(comment, CommonOperations.Update);

            comment.SetText(input.Text);

            comment = await _commentRepository.UpdateAsync(comment);

            return(ObjectMapper.Map <Comment, CommentWithDetailsDto>(comment));
        }
        public async void Comments_PUT_Returns_200()
        {
            UpdateCommentDto updatedComment = new UpdateCommentDto()
            {
                Text = string.Empty
            };

            Post post = await CreatePost();

            Comment createComment = await CreateComment(post);

            var response = await this.HttpClient.PutAsync($"/api/v1/comments/{createComment.Id}", new StringContent(JsonConvert.SerializeObject(updatedComment), Encoding.UTF8, "application/json"));

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
示例#20
0
        public IActionResult UpdateComment(int id, [FromBody] UpdateCommentDto updatedComment)
        {
            try
            {
                if (_user != null || _admin != null)
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }

                    var commentStore = new CommentEntity();
                    var dbResult     = new List <CommentEntity>();
                    if (_admin != null)
                    {
                        var result = _ctx.GetCommentsByAvatar(admin: _admin.Id);
                        commentStore = dbResult.Where(c => c.Id == id).FirstOrDefault();
                    }
                    else
                    {
                        if (updatedComment.FlaggedCommentMessages != null)
                        {
                            dbResult = _ctx.GetAllComment().Result.ToList();
                        }
                        else
                        {
                            dbResult = _ctx.GetCommentsByAvatar(_user.Id).ToList();
                        }
                    }
                    commentStore = dbResult.Where(c => c.Id == id).FirstOrDefault();
                    updatedComment.LastUpdatedOn = DateTime.Now;
                    _mapper.Map(updatedComment, commentStore);

                    if (_ctx.UpdateContent(commentStore))
                    {
                        return(Ok($"Comment with ID: {id} has been updated."));
                    }
                    return(BadRequest("No update was made"));
                }
                return(Unauthorized(Message("unautherized")));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Unable to Update comment: {id}.", ex);
                return(StatusCode(500, "There was an expection found at UpdateComment."));
            }
        }
示例#21
0
 public IActionResult Put(string id, [FromBody] UpdateCommentDto obj)
 {
     obj.Id = id;
     try
     {
         _updateComment.Execute(obj);
         return(NoContent());
     }
     catch (EntityNotFoundException)
     {
         return(NotFound());
     }
     catch
     {
         return(StatusCode(500));
     }
 }
示例#22
0
        public async Task <CommentDto> UpdateMyCommentAsync(long commentId, UpdateCommentDto updateComment)
        {
            var commentEntity = await _context
                                .Comments
                                .Include(c => c.CreatedBy)
                                .Where(c => c.Id == commentId)
                                .SingleOrDefaultAsync();

            ThrowNotFoundIfNull(commentEntity);
            ThrowForbiddenIfNotCreatedByCurrentUser(commentEntity);

            _mapper.Map(updateComment, commentEntity);

            await _context.SaveChangesAsync();

            return(_mapper.Map <CommentDto>(commentEntity));
        }
        public async Task <IActionResult> DeleteComment(UpdateCommentDto dto)
        {
            var comment = await _repos.GetById(dto.Id);

            if (comment == null)
            {
                return(BadRequest("No such comment"));
            }
            if (!string.IsNullOrEmpty(dto.Description))
            {
                comment.Description = dto.Description;
            }
            if (await _repos.Update(comment))
            {
                return(Ok("Updated comment"));
            }
            return(StatusCode(500));
        }
示例#24
0
        public async Task <IActionResult> Update([FromRoute] string commentId,
                                                 [FromBody] UpdateCommentDto updateCommentDto)
        {
            Comment comment = await _mediator.Send(new GetCommentEntityQuery(commentId));

            AuthorizationResult authorizationResult =
                await _authorizationService.AuthorizeAsync(User, comment, PolicyConstants.UpdateCommentRolePolicy);

            if (!authorizationResult.Succeeded)
            {
                return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated));
            }

            return(Ok(new Response <CommentViewModel>
            {
                Data = await _mediator.Send(new UpdateCommentCommand(comment, updateCommentDto)),
            }));
        }
示例#25
0
        public async Task Update(string postId, string id, UpdateCommentDto dto)
        {
            User user = await _sessionService.GetUser();

            Validate("modify", dto.Content, user);

            Comment comment = await _commentRepository.GetById(id);

            if (comment == null)
            {
                _logger.LogWarning($"Comment {id} does not exist");
                throw HttpError.NotFound($"Comment {id} does not exist");
            }

            if (comment.PostId != postId)
            {
                throw HttpError.NotFound("");
            }

            if (comment.AuthorId != user.Id)
            {
                _logger.LogWarning($"Comment {id} does not belong to user");
                throw HttpError.Forbidden($"Comment {id} does not belong to user");
            }

            comment.Content        = dto.Content;
            comment.LastUpdateTime = DateTime.Now;

            bool success = await _commentRepository.Update(comment);

            if (!success)
            {
                _logger.LogWarning("Error during update comment");
                throw HttpError.InternalServerError("");
            }
        }
示例#26
0
 public Task <CommentDto> UpdateMyComment([FromRoute] long commentId, [FromBody] UpdateCommentDto updateComment)
 {
     return(_commentService.UpdateMyCommentAsync(commentId, updateComment));
 }
示例#27
0
 public Task <CommentWithDetailsDto> UpdateAsync(Guid id, UpdateCommentDto input)
 {
     return(_commentAppService.UpdateAsync(id, input));
 }
示例#28
0
 public ActionResult <IdDto> UpdateComment(int id, [FromBody] UpdateCommentDto updateCommentDto)
 {
     return(new OkObjectResult(new { Id = _commentService.UpdateComment(id, updateCommentDto) }));
 }
示例#29
0
 public async Task Update(Guid id, UpdateCommentDto commentDto)
 {
     await _commentAppService.UpdateAsync(id, commentDto);
 }
示例#30
0
        public async Task <IActionResult> Update([FromRoute] string postId, string id, [FromBody] UpdateCommentDto dto)
        {
            await _commentService.Update(postId, id, dto);

            return(NoContent());
        }