コード例 #1
0
        public async Task <IActionResult> Create([FromBody] CommentViewModel model, [FromRoute] int coachId, CancellationToken ct)
        {
            var comment = model.Adapt <Comment>();
            var coach   = await _coachService.GetAsync(coachId, ct);

            if (coach == null)
            {
                return(BadRequest());
            }

            var user = await GetCurrentUserAsync();

            if (user.Coach?.Id == coachId)
            {
                return(BadRequest());
            }

            comment.Coach = coach;
            comment.User  = user;

            await _commentService.CreateAsync(comment, ct);

            return(Ok(comment.Id));
        }