コード例 #1
0
        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));
        }
コード例 #2
0
        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
            });
        }