コード例 #1
0
        public IActionResult CreateComment([FromRoute] Guid activityId, [FromBody] CommentCreateDto commentCreateDto)
        {
            if (!_activityRepository.ActivityExists(activityId))
            {
                return(NotFound("活动不存在"));
            }

            var CommentModel = _mapper.Map <Comment>(commentCreateDto);

            _activityRepository.AddComment(activityId, CommentModel);
            _activityRepository.Save();
            var CommentReturn = _mapper.Map <CommentDto>(CommentModel);

            return(CreatedAtRoute("GetComment",
                                  new { activityId = CommentModel.ActivityId, CommentId = CommentModel.Id },
                                  CommentReturn));
        }