Exemple #1
0
        public async Task <UserDetailInformationDto> Handle(UserByIdDetailInformationQuery request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var user = await _context.Users
                       .Include(u => u.Team)
                       .Include(u => u.Projects)
                       .Include(u => u.Tasks)
                       .SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken);

            if (user is null)
            {
                throw new NotFoundException(nameof(user));
            }

            var inProcess = new List <TaskState>()
            {
                TaskState.Canceled, TaskState.Started, TaskState.Created
            };

            var lastProject = user.Projects?
                              .OrderByDescending(p => p.CreatedAt)
                              .FirstOrDefault();

            var userInfoDto = new UserDetailInformationDto
            {
                User               = _mapper.Map <UserDto>(user),
                LastProject        = _mapper.Map <ProjectDto>(lastProject),
                TasksCount         = lastProject is null ? 0 : user.Tasks.Where(t => t.ProjectId == lastProject.Id).Count(),
                TasksCanceledCount = user.Tasks.Where(t => inProcess.Contains(t.TaskState)).Count(),
                LongestTask        = _mapper.Map <TaskDto>(user.Tasks.OrderBy(t => t.FinishedAt - t.CreatedAt).FirstOrDefault())
            };

            return(userInfoDto);
        }
    }
 public Task <IActionResult> GetUserInformationFullById(UserByIdDetailInformationQuery query) => ExecuteQuery(query);