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 <TaskDetailsDto> Handle(CreateNewTaskCommand request, CancellationToken cancellationToken)
        {
            var taskToAdd = _mapper.Map <Tasks>(request.TaskForCreationDto);

            taskToAdd.TrackerId = _authService.UserRoleAdmin()
                ? new Guid(_authService.GetUserIdClaimValue())
                : taskToAdd.TrackerId;

            if (taskToAdd.TrackerId != null)
            {
                var userToMap = await _userService
                                .GetUserAsync(taskToAdd.TrackerId ??
                                              throw new ArgumentNullException());

                taskToAdd.TrackerFirstName = userToMap.FirstName;
                taskToAdd.TrackerLastName  = userToMap.LastName;
            }

            await _tasksService.AddTask(taskToAdd);

            var taskFromDbForMapping = await _tasksService.GetTaskWithEagerLoadingAsync(taskToAdd.Id);

            var taskToReturn = _mapper.Map <TaskDetailsDto>(taskFromDbForMapping);
            await _emailService.SendEmailAsync(taskFromDbForMapping);

            return(taskToReturn);
        }
Esempio n. 3
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));
        }