Esempio n. 1
0
        public async Task <CommentDetailsDto> Handle(GetCommentQuery request, CancellationToken cancellationToken)
        {
            if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId))
            {
                throw new AuthenticationException();
            }

            var commentFromDb = await _commentService.GetCommentAsync(request.CommentId);

            return(_mapper.Map <CommentDetailsDto>(commentFromDb));
        }
Esempio n. 2
0
        public async Task <TeamDetailsDto> Handle(GetSingleTeamQuery request, CancellationToken cancellationToken)
        {
            var teamFromDb = await _teamService.GetTeamWithEagerLoadingAsync(request.TeamId);

            if (_authService.UserRoleAdminOrTeamIdMatches(teamFromDb))
            {
                return(_mapper.Map <TeamDetailsDto>(teamFromDb));
            }

            throw new AuthenticationException();
        }
Esempio n. 3
0
        public async Task <TaskDetailsDto> Handle(GetSingleTaskForTeamQuery request,
                                                  CancellationToken cancellationToken)
        {
            if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId))
            {
                throw new AuthenticationException("Unauthorized access.");
            }

            var taskFromDb = await _taskService.GetTaskWithEagerLoadingAsync(request.TaskId);

            return(_mapper.Map <TaskDetailsDto>(taskFromDb));
        }
Esempio n. 4
0
        public async Task <IEnumerable <CommentDetailsDto> > Handle(GetAllCommentsQuery request,
                                                                    CancellationToken cancellationToken)
        {
            if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId))
            {
                throw new AuthenticationException();
            }

            var commentsToReturn = await _commentService.GetAllCommentsAsync(request.TaskId);

            return(_mapper.Map <IEnumerable <CommentDetailsDto> >(commentsToReturn));
        }
Esempio n. 5
0
        public async Task <CommentDetailsDto> Handle(CreateNewCommentCommand request, CancellationToken cancellationToken)
        {
            if (!_authService.UserRoleAdminOrTeamIdMatches(request.CommentForCreationDto.TeamId))
            {
                throw new AuthenticationException();
            }

            request.CommentForCreationDto.UserId = new Guid(_authService.GetUserIdClaimValue());

            var commentToAdd = _mapper.Map <Comment>(request.CommentForCreationDto);
            await _commentService.AddNewCommentAsync(commentToAdd);

            return(_mapper.Map <CommentDetailsDto>(commentToAdd));
        }
Esempio n. 6
0
        public async Task <IEnumerable <TaskDetailsDto> > Handle(GetAllTasksForTeamQuery request,
                                                                 CancellationToken cancellationToken)
        {
            if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId))
            {
                throw new AuthenticationException("Access denied");
            }

            var tasksFromDb = await _taskService.GetAllTasksForATeamAsync(request.TeamId);

            var tasksToReturn = tasksFromDb.Select(t => _mapper.Map <TaskDetailsDto>(t));

            return(tasksToReturn);
        }