public async Task <ActionResult <BrainTeaserCommentDto> > AddComment(int id, BrainTeaserCommentRequest model) { var brainTeaser = await _repository.GetById(id); if (brainTeaser == null) { return(NotFound(BrainTeaserNotFound)); } var result = await _repository.AddComment(id, model); return(result != null ? Created(nameof(AddComment), result) : StatusCode(StatusCodes.Status500InternalServerError, null)); }
public async Task <BrainTeaserCommentDto> AddComment(int id, BrainTeaserCommentRequest model) { var comment = new BrainTeaserComment { Body = model.Body, Name = model.Name, BrainTeaserId = id }; _db.BrainTeaserComments.Add(comment); await _db.SaveChangesAsync(); return(new BrainTeaserCommentDto { Body = comment.Body, Id = comment.Id, Name = comment.Body, CreatedAt = comment.CreatedAt }); }