public async Task AddComment(AddMovieCommentDTO addMovieCommentDTO, ClaimsPrincipal sessionUser)
        {
            var targetUser = await GetUserByClaimCheckNullAsync(sessionUser);

            _movieCommmentRepository.Add(DTOToModel.AddMovieCommentDTOToModel(addMovieCommentDTO, targetUser.Id));
            await _movieCommmentRepository.SaveEntitiesAsync();
        }
        public async Task <IActionResult> Add(AddMovieCommentDTO addMovieCommentDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _movieCommentService.AddComment(addMovieCommentDTO, User);

                    TempData["AddCommentNote"] = "Your comment has been posted.It will show up after approval.";

                    return(RedirectToAction("Details", "Movie", new { id = addMovieCommentDTO.MovieId }));
                }

                TempData["AddCommentError"] = "Please insert valid format!";

                return(RedirectToAction("Details", "Movie", new { id = addMovieCommentDTO.MovieId }));
            }
            catch (FlowException ex)
            {
                TempData["AddCommentError"] = ex.Message;

                return(RedirectToAction("Details", "Movie", new { id = addMovieCommentDTO.MovieId }));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Ejemplo n.º 3
0
 public static MovieComment AddMovieCommentDTOToModel(AddMovieCommentDTO addMovieCommentDTO, int userId)
 {
     return(new MovieComment()
     {
         Comment = addMovieCommentDTO.Comment,
         UserId = userId,
         MovieId = addMovieCommentDTO.MovieId
     });
 }