//Ne treba // PUT: api/Comment/5 public bool Put(int id, [FromBody] UpdateCommentDTO comment) { if (comment != null) { return(service.UpdateComment(comment)); } return(false); }
public bool UpdateComment(UpdateCommentDTO dto) { bool ret = false; using (UnitOfWork uw = new UnitOfWork()) { Comment c = uw.CommentRepository.GetById(dto.CommentId); if (c != null) { c.Text = dto.Text; uw.CommentRepository.Update(c); ret = uw.Save(); } } return(ret); }
public IActionResult Put(Guid id, [FromBody] UpdateCommentDTO updateCommentDto) { if (updateCommentDto == null) { return(BadRequest()); } var comment = _repository.GetById(id); if (comment == null) { return(NotFound()); } //comment.Update(comment.TransportationMean, comment.User, DateTime.Now, updateCommentDto.Text, 0, // updateCommentDto.Rating); comment = Mapper.Map(updateCommentDto, comment); _repository.Update(comment); return(NoContent()); }
public async Task <IActionResult> Update([FromBody] UpdateCommentDTO updateCommentDTO) { if (ModelState.IsValid) { string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; try { Comment comm = _commentRepo.FindById(updateCommentDTO.CommentId); comm.Content = updateCommentDTO.Content; _commentRepo.Update(comm, userId); _commentRepo.Save(); return(Ok()); } catch (Exception ex) { throw new Exception(ex.Message); } } else { return(BadRequest()); } }