コード例 #1
0
ファイル: CommentService.cs プロジェクト: boolbinos/InTouch
 public async Task <IEnumerable <CommentDTO> > FindValidAsync(Expression <Func <Comment, bool> > predicate)
 {
     return((await _db.Comments.FindValidAsync(predicate)).Select(c =>
     {
         CommentDTO commentDTO = CommentMapper.ConvertToCommentDTO(c);
         commentDTO.UserDTO = UserMapper.ConvertToUserDTO(c.User);
         return commentDTO;
     }));
 }
コード例 #2
0
ファイル: CommentService.cs プロジェクト: boolbinos/InTouch
        public async Task <CommentDTO> GetCommentAsync(int id)
        {
            var comment = await _db.Comments.GetAsync(id);

            var commentDTO = CommentMapper.ConvertToCommentDTO(comment);

            commentDTO.UserDTO = UserMapper.ConvertToUserDTO(comment.User);

            return(commentDTO);
        }
コード例 #3
0
ファイル: CommentService.cs プロジェクト: boolbinos/InTouch
        public async Task <IEnumerable <CommentDTO> > GetCommentsByPostAsync(int postId)
        {
            var comments = await _db.Comments.GetAllByPost(postId);

            var commentsDTO = comments.Select(c =>
            {
                var commentDTO     = CommentMapper.ConvertToCommentDTO(c);
                commentDTO.UserDTO = UserMapper.ConvertToUserDTO(c.User);
                return(commentDTO);
            });

            return(commentsDTO);
        }
コード例 #4
0
ファイル: CommentService.cs プロジェクト: boolbinos/InTouch
        public async Task <IEnumerable <CommentDTO> > GetCommentsByUserAsync(int userId)
        {
            var comments = await _db.Comments.GetAllByUser(userId);

            var commentsDTO = comments.Select(c =>
            {
                var commentDTO = CommentMapper.ConvertToCommentDTO(c);
                //commentDTO.UserDTO = UserMapper.ConvertToUserDTO(c.User);
                //commentDTO.PostDTO = PostMapper.ConvertToPostDTO(c.Post);
                return(commentDTO);
            });

            return(commentsDTO);
        }
コード例 #5
0
ファイル: CommentService.cs プロジェクト: boolbinos/InTouch
        public async Task <IEnumerable <CommentDTO> > GetCommentsAsync()
        {
            var comments = await _db.Comments.GetAllValidAsync();

            var commentsDTO = comments.Select(u =>
            {
                var commentDTO     = CommentMapper.ConvertToCommentDTO(u);
                commentDTO.UserDTO = UserMapper.ConvertToUserDTO(u.User);

                return(commentDTO);
            });

            return(commentsDTO);
        }
コード例 #6
0
ファイル: CommentService.cs プロジェクト: boolbinos/InTouch
        public async Task <CommentDTO> CreateAsync(CommentDTO comment)
        {
            var currentUser = _userContext.CurrentUser;

            if (comment.CreatedDate == default(DateTime))
            {
                comment.CreatedDate = DateTime.Now;
            }
            comment.UserId = currentUser.Id;

            var commentToSave = CommentMapper.ConvertToComment(comment);

            var createdComment = await _db.Comments.CreateAsync(commentToSave);

            await _db.SaveAsync();

            var createdCommentDTO = CommentMapper.ConvertToCommentDTO(createdComment);

            createdCommentDTO.UserDTO = currentUser;
            return(createdCommentDTO);
        }
コード例 #7
0
        public async Task <IActionResult> CreateAsync([FromBody] CommentCreateModel commentCreateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (commentCreateModel == null)
            {
                return(BadRequest());
            }

            if (commentCreateModel.Content.Length > 8000)
            {
                return(BadRequest());
            }

            var comment        = CommentMapper.ConvertToCommentDTO(commentCreateModel);
            var createdComment = await _commentService.CreateAsync(comment);

            var commentViewModel = CommentMapper.ConvertToCommentViewModel(createdComment);


            var post = await _postService.GetAsync(comment.PostId);

            var commentators = (await _commentService.FindValidAsync(c =>
                                                                     c.PostId == comment.PostId &&
                                                                     c.User.Email != post.UserDTO.Email &&
                                                                     c.UserId != comment.UserId))
                               .Select(c => new CommentEmailModel()
            {
                Email     = c.UserDTO.Email,
                FirstName = c.UserDTO.FirstName,
                LastName  = c.UserDTO.LastName
            }).Distinct().ToList();

            _emailSender.PostCommentNotificationAsync(commentViewModel, post, commentators);
            return(Ok(commentViewModel));
        }