public async Task UpdateCommentAsync(int commentId, SaveCommentDto commentDto) { var comment = await _repository.GetAsync(commentId); commentDto.UpdateDateTime = DateTime.Now; _mapper.Map(commentDto, comment); await _repository.SaveAsync(); }
public async Task <IActionResult> CreateComment(int beerId, [FromBody] SaveCommentDto commentDto) { if (!await _service.IfBeerExistAsync(beerId)) { return(NotFound()); } var userLogged = int.Parse(HttpContext.User.Identity.Name); var result = await _service.CreateCommentAsync(userLogged, beerId, commentDto); return(CreatedAtRoute("GetComment", new { beerId, commentId = result.Id }, result)); }
public async Task <IActionResult> UpdateComment(int beerId, int commentId, [FromBody] SaveCommentDto commentDto) { if (!await _service.IfBeerExistAsync(beerId)) { return(NotFound()); } if (!await _service.IfExistComment(commentId)) { return(NotFound()); } await _service.UpdateCommentAsync(commentId, commentDto); return(Ok()); }
public async Task <CommentDto> CreateCommentAsync(int userLogged, int beerId, SaveCommentDto commentDto) { var comment = _mapper.Map <SaveCommentDto, Comment>(commentDto); comment.BeerId = beerId; comment.UserId = userLogged; comment.CreateDateTime = DateTime.Now; await _repository.AddAsyn(comment); await _repository.SaveAsync(); return(await GetCommentAsync(comment.Id)); }