예제 #1
0
 public async Task Post([FromBody] CommentRequestViewModel input)
 {
     if (this.essayService.HasEssayWithId(input.EssayId) && string.IsNullOrEmpty(input.CommentContent) != true)
     {
         var userId = this.userManager.GetUserId(this.User);
         await this.commentService.AddCommentAsync(userId, input.EssayId, input.CommentContent);
     }
 }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [FromForm] CommentRequestViewModel commentModel)
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <CommentRequestViewModel, CommentRequestDto>())
                         .CreateMapper();

            var commentDto = mapper.Map <CommentRequestDto>(commentModel);

            await _newsCommentService.UpdateComment(id, commentDto);

            return(Ok());
        }
예제 #3
0
        public async Task <IActionResult> CreateComment(CommentViewModel model)
        {
            var viewModel = new CommentRequestViewModel();

            viewModel.userName = model.newComment.userName;
            viewModel.Message  = model.newComment.Message;
            viewModel.PostId   = model.newComment.PostId;


            var commentRequest = JsonConvert.SerializeObject(viewModel);
            var content        = new StringContent(commentRequest, Encoding.UTF8, "application/json");
            var response       = await httpClient.PostAsync("api/comment", content);


            if (!response.IsSuccessStatusCode)
            {
                return(Redirect("/Home/Index"));
            }


            return(Redirect("/"));
        }