Ejemplo n.º 1
0
        public async Task <List <StatusModel> > Handle(GetAllStatusQuery request, CancellationToken cancellationToken)
        {
            var user = await userStore.FindByIdAsync(request.GetUser(), cancellationToken);

            if (user == null)
            {
                throw new UserDoesNotExistException();
            }

            var statusDb = await _statusRepository.GetAllStatusAsync();

            var workersDb = await _workerRepository.GetAllWorkersAsync();

            var groupByStatusId = workersDb
                                  .GroupBy(x => x.Status)
                                  .Select(w => new StatusModel(w.Key.StatusId, w.Count())
                                          );

            var response = statusDb.Select(x =>
                                           new StatusModel(statusId: x.StatusId,
                                                           statusName: x.Name)
            {
                TotalWorkers = groupByStatusId.Any(y => y.StatusId == x.StatusId)
                                                        ? groupByStatusId.Where(y => y.StatusId == x.StatusId).Select(y => y.TotalWorkers).FirstOrDefault()
                                                        : 0
            })
                           .ToList();

            return(response);
        }
Ejemplo n.º 2
0
 public async Task<IEnumerable<Status>> GetAllStatusAsync()
 {
     return await stateRepository.GetAllStatusAsync();
 }