Пример #1
0
        public async Task <int> AddUserCommentAsync(CommentCreationDTO commentCreationDTO)
        {
            var user = await _accountsService.GetCurrentUserAsync();

            commentCreationDTO.UserId = user.Id;
            commentCreationDTO.Type   = 2;

            return(await _commentService.SaveCommentAsync(commentCreationDTO));
        }
Пример #2
0
        public async Task <ActionResult <SubCommentDTO> > PostSub(CommentCreationDTO commentCreationDTO)
        {
            if (commentCreationDTO.IsMain)
            {
                return(BadRequest());
            }

            var subCommentDTO = await _commentService.InsertSubCommentAsync(commentCreationDTO);

            return(new CreatedAtRouteResult("getSub", new { subCommentDTO.ID }, subCommentDTO));
        }
Пример #3
0
        public async Task <ActionResult <MainCommentDTO> > PostMain(CommentCreationDTO commentCreationDTO)
        {
            if (!commentCreationDTO.IsMain)
            {
                return(BadRequest());
            }

            var mainCommentDTO = await _commentService.InsertMainCommentAsync(commentCreationDTO);

            return(new CreatedAtRouteResult("getMain", new { mainCommentDTO.ID }, mainCommentDTO));
        }
Пример #4
0
        public async Task <ActionResult> AddComment([FromBody] CommentCreationDTO commentCreationDTO)
        {
            var result = await _moviesService.AddUserCommentAsync(commentCreationDTO);

            if (result == -1)
            {
                return(NotFound());
            }
            else if (result == 0)
            {
                return(BadRequest("Failed to save changes."));
            }

            return(NoContent());
        }
Пример #5
0
        public async Task <MainCommentDTO> InsertMainCommentAsync(CommentCreationDTO commentCreationDTO)
        {
            Preconditions.NotNull(commentCreationDTO, nameof(commentCreationDTO));

            if (!commentCreationDTO.IsMain)
            {
                throw new InvalidOperationException("Can not insert the SubComment into MainComment Table");
            }

            var mainCommentEntity = _mapper.Map <MainComment>(commentCreationDTO);

            mainCommentEntity.ApplicationUserID = await _currentUserProvider.GetCurrentUserIDAsync();

            var insertedMainComment = await _commentRepository.InsertMainCommentAsync(mainCommentEntity);

            return(_mapper.Map <MainCommentDTO>(insertedMainComment));
        }
Пример #6
0
        public async Task <int> SaveCommentAsync(CommentCreationDTO commentCreationDTO)
        {
            var movie   = new Movie();
            var serie   = new Serie();
            var comment = new Comment();

            if (commentCreationDTO.MovieId != null)
            {
                movie = await _dbContext.Movies.FirstOrDefaultAsync(x => x.Id == commentCreationDTO.MovieId);

                comment = _mapper.Map <Comment>(commentCreationDTO);
                movie.Comments.Add(comment);
            }
            else if (commentCreationDTO.SerieId != null)
            {
                serie = await _dbContext.Series.FirstOrDefaultAsync(x => x.Id == commentCreationDTO.SerieId);

                comment = _mapper.Map <Comment>(commentCreationDTO);
                serie.Comments.Add(comment);
            }
            else
            {
                _logger.LogWarn($"Failed to add new comment. No MovieId or SerieId was given.");
                return(-2);
            }

            try
            {
                await _dbContext.SaveChangesAsync();

                _logger.LogInfo($"Comment with ID {comment.Id} was added successfully.");
                return(1);
            }
            catch (System.Exception ex)
            {
                _logger.LogWarn($"Failed to add comment with ID {comment.Id}. Exception: {ex}");
                return(-1);
            }
        }
Пример #7
0
 public async Task <SubCommentDTO> InsertSubCommentAsync(CommentCreationDTO commentCreationDTO)
 {
     return(await _httpService.PostHelperAsync <CommentCreationDTO, SubCommentDTO>(CommentClientEndpoints.SubBase, commentCreationDTO));
 }