Esempio n. 1
0
        public async Task <bool> DeleteComment(string commentId)
        {
            var user = await profileService.GetCurrentUser();

            var comment = user.Comments.FirstOrDefault(c => c.Id == commentId) ?? await database.CommentRepository.FindById(commentId)
                          ?? throw new EntityNotFoundException("Comment not found");

            if (!UpdateOrDeleteCommentSpecification.Create(user).IsSatisfied(comment))
            {
                throw new NoPermissionsException("You have no permissions to perform this action");
            }

            database.CommentRepository.Delete(comment);

            return(await database.Complete());
        }
Esempio n. 2
0
        public async Task <Comment> UpdateComment(string content, Comment currentComment)
        {
            var user = await profileService.GetCurrentUser();

            if (!UpdateOrDeleteCommentSpecification.Create(user).IsSatisfied(currentComment))
            {
                throw new NoPermissionsException("You are not allowed to update this post");
            }

            currentComment.SetContent(content);
            currentComment.Update();

            database.CommentRepository.Update(currentComment);

            return(await database.Complete() ? currentComment : null);
        }