示例#1
0
        public async Task <PostCommentResponseDto> CreateAndReturnDtoAsync
            (TransferredResponseToResponseDto responseDto, int authorId, IFormFile file)
        {
            string imagePath;

            if (file != null)
            {
                imagePath = await _imageSaver
                            .SaveAndReturnImagePath(file, "ResponseToComment",
                                                    responseDto.ResponseToCommentId);
            }
            var responseToResponse = new ResponseToComment
            {
                Comment = new Models.Comment()
                {
                    Content = responseDto.Content,
                    UserId  = authorId,
                    PostId  = responseDto.PostId,
                    Date    = DateTime.Now
                },
                ResponseToCommentId = responseDto.ResponseToCommentId,
                MainCommentId       = responseDto.MainCommentId
            };

            _unitOfWork.ResponseToCommentRepository
            .Add(responseToResponse);
            _unitOfWork.SaveChanges();
            return(await _repository.ResponseToComment.GetByIdAsync(responseToResponse.Id,
                                                                    PostCommentResponseDto.Selector(authorId)));
        }
示例#2
0
        public async Task <PostCommentResponseDto> CreateAndReturnDtoAsync(
            NewCommentResponseDto commentResponseDto, int authorId,
            IFormFile file)
        {
            string imagePath;

            if (file != null)
            {
                imagePath = await _imageSaver
                            .SaveAndReturnImagePath(file, "ResponseToCommentResponse",
                                                    commentResponseDto.CommentId);
            }
            var responseToResponse = new ResponseToComment
            {
                Comment = new Models.Comment()
                {
                    Content = commentResponseDto.Content,
                    UserId  = authorId,
                    PostId  = commentResponseDto.PostId,
                    Date    = DateTime.Now
                },
                ResponseToCommentId = null,
                MainCommentId       = commentResponseDto.CommentId
            };

            _repository.ResponseToComment.Add(responseToResponse);
            await _repository.SaveAsync();

            return(await _repository.ResponseToComment.GetByIdAsync(responseToResponse.Id,
                                                                    PostCommentResponseDto.Selector(authorId)));
        }
示例#3
0
        GetAllCommentResponsesAsync(int commentId,
                                    int userId)
        {
            var posts = await _repository.ResponseToComment
                        .GetAllByMainCommentIdAsync(commentId,
                                                    PostCommentResponseDto.Selector(userId));

            return(posts);
        }