Beispiel #1
0
        public IActionResult AddNewComment(int taskId, string commentText)
        {
            if (string.IsNullOrEmpty(commentText) || string.IsNullOrWhiteSpace(commentText))
            {
                return(Json(new
                {
                    success = false,
                    errorMessage = "Comment cannot be empty."
                }));
            }

            var task = _taskRepository.Get(taskId);

            if (task == null)
            {
                return(Json(new
                {
                    success = false,
                    errorMessage = "Invalid Task."
                }));
            }

            var comment = new CommentDTO
            {
                Author = new UserDTO {
                    Id = _appContext.UserId.Value
                },
                Text = commentText,
                Task = task
            };

            var id = _commentManager.Create(comment);

            return(Json(new
            {
                success = true,
                id
            }));
        }
Beispiel #2
0
 public async Task <ApiResponse> Post([FromBody] CommentDto comment)
 => ModelState.IsValid ?
 await _commentManager.Create(comment) :
 new ApiResponse(Status400BadRequest, "Comment Model is Invalid");
 public async Task Create(CreateCommentInput input)
 {
     Models.Comment output = Mapper.Map <CreateCommentInput, Models.Comment>(input);
     await _commentManager.Create(output);
 }