Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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));
        }