public async Task <ParkQuery> GetTotalsAsync(Guid userID) { var company = await _userCompanyRepository.FirstOrDefaultAsync(x => x.UserID.Equals(userID.ToString())); if (company == null) { throw new CustomExceptions("Estacionamento não encontrado"); } var totalInput = await _parkingRepository.CountAsync(x => x.CompanyID == company.CompanyID && x.EndDate == null); var totalOut = await _parkingRepository.CountAsync(x => x.CompanyID == company.CompanyID && x.EndDate != null); return(new ParkQuery { TotalInput = totalInput, TotalOut = totalOut }); }
private async Task <short> QtdAsync(Guid companyID, short value, TypeEnum type) { if (type == TypeEnum.CARS) { var count = await _parkingRepository.CountAsync(x => x.CompanyID == companyID && x.EndDate == null && x.Vehicle.TypeID == 1, new string[] { "Vehicle" }); if (value < count) { throw new CustomExceptions($"Não é possível reduzir a capacidade total de carros no estacionamento pois há {count} carros"); } } else if (type == TypeEnum.MOTORCYCLES) { var count = await _parkingRepository.CountAsync(x => x.CompanyID == companyID && x.EndDate == null && x.Vehicle.TypeID == 2, new string[] { "Vehicle" }); if (value < count) { throw new CustomExceptions($"Não é possível reduzir a capacidade total de motos no estacionamento pois há {count} carros"); } } return(value); }