Esempio n. 1
0
        public async Task <TaskDetailsDto> Handle(AddLogToATaskCommand request, CancellationToken cancellationToken)
        {
            var taskFromDb = await _taskService.GetTaskWithEagerLoadingAsync(request.LogForCreationDto.TasksId);

            if (!_authService.UserRoleAdminOrUserIdMatches(taskFromDb.UserId))
            {
                throw new AuthenticationException();
            }

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

            var logToAdd = _mapper.Map <LoggedActivity>(request.LogForCreationDto);
            await _logService.AddNewLogAsync(logToAdd);

            await _taskService.CalculateNewWorkBalanceAsync(taskFromDb, logToAdd);

            await _emailService.SendEmailIfStatusChangedAsync(taskFromDb, request.LogForCreationDto.TaskStatus);

            await _taskService.ChangeStatusBasedOnAdminApproval(taskFromDb, request.LogForCreationDto);

            var teamForUpdate = await _teamService.GetTeamWithoutEagerLoadingAsync(request.LogForCreationDto.TeamId);

            await _teamService.CalculateTotalHoursOfWorkAsync(teamForUpdate, logToAdd);

            return(_mapper.Map <TaskDetailsDto>(taskFromDb));
        }
Esempio n. 2
0
        public async Task <IEnumerable <LogDetailsDto> > Handle(GetAllLogsForTaskQuery request, CancellationToken cancellationToken)
        {
            var taskFromDb = await _tasksService.GetTaskWithoutEagerLoadingAsync(request.TaskId);

            if (!_authService.UserRoleAdminOrUserIdMatches(taskFromDb.UserId))
            {
                throw new AuthenticationException();
            }

            var logsFromDb = await _logService.GetAllLogsAsync(request.TaskId);

            return(_mapper.Map <List <LogDetailsDto> >(logsFromDb));
        }
Esempio n. 3
0
        public async Task <LogDetailsDto> Handle(GetLogForTaskCommand request, CancellationToken cancellationToken)
        {
            var taskFromDb = await _taskService.GetTaskWithoutEagerLoadingAsync(request.TaskId);

            if (!_authService.UserRoleAdminOrUserIdMatches(taskFromDb.UserId))
            {
                throw new AuthenticationException();
            }

            var logFromDb = await _logService.GetLogAsync(request.LogId);

            return(_mapper.Map <LogDetailsDto>(logFromDb));
        }
Esempio n. 4
0
        public async Task <TaskDetailsDto> Handle(AssignUserToTaskCommand request, CancellationToken cancellationToken)
        {
            var taskFromDb = await _taskService.GetTaskWithEagerLoadingAsync(request.TaskId);

            if (!_authService.UserRoleAdminOrUserIdMatches(request.UserId))
            {
                throw new AuthenticationException("You don't have permission to assign anyone else beside yourself to a task.");
            }

            await _taskService.AddUserToTaskAsync(taskFromDb, request.UserId);

            return(_mapper.Map <TaskDetailsDto>(taskFromDb));
        }
Esempio n. 5
0
        public async Task <CommentDetailsDto> Handle(UpdateCommentCommand request, CancellationToken cancellationToken)
        {
            var taskFromDb = await _taskService.GetTaskWithoutEagerLoadingAsync(request.CommentForUpdateDto.TaskId);

            if (!_authService.UserRoleAdminOrUserIdMatches(taskFromDb.UserId))
            {
                throw new AuthenticationException();
            }

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

            await _commentService.UpdateComment(commentFromDb, request.CommentForUpdateDto);

            return(_mapper.Map <CommentDetailsDto>(commentFromDb));
        }