Esempio n. 1
0
        public async Task <PostCommentDto> CreateAndReturnMainCommentAsync(NewCommentDto
                                                                           commentDto, int authorId, IFormFile file)
        {
            string imagePath;

            if (file != null)
            {
                imagePath = await _imageSaver
                            .SaveAndReturnImagePath(file, "Comment",
                                                    commentDto.PostId);
            }
            var newComment = new MainComment
            {
                Comment = new Models.Comment()
                {
                    PostId  = commentDto.PostId,
                    Content = commentDto.Content,
                    Date    = DateTime.Now,
                    UserId  = authorId
                }
            };

            _repository.MainComment.CreateMainComment(newComment);
            await _repository.SaveAsync();

            var createdComment = _repository.MainComment.FindById(newComment.Id,
                                                                  PostCommentDto.Selector(authorId));

            return(createdComment);
        }
Esempio n. 2
0
        public async Task <IEnumerable <PostCommentDto> > GetAllMainByPostIdAsync(int postId,
                                                                                  int userId)
        {
            var posts = await _repository
                        .MainComment
                        .GetAllByPostIdAsync(postId, PostCommentDto.Selector(userId));

            return(posts);
        }