Example #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));
        }