public async Task <bool> Handle(DeleteChargeStationCommand command, CancellationToken cancellationToken) { var stationFound = await _stationRepository.ExistsAsync(command.Id).ConfigureAwait(false); if (!stationFound) { throw new ChargeStationNotFoundException(command.Id); } var station = await _stationRepository.GetAsync(command.Id); if (station.ParentChargeGroup == null) { throw new ChargeGroupNotFoundException(command.Id); } var group = await _groupRepository.GetAsyncExtended(station.ParentChargeGroup.Id); group.RemoveChargeStation(station.Id); await _groupRepository.UpdateAsync(group).ConfigureAwait(false); await _stationRepository.DeleteAsync(command.Id).ConfigureAwait(false); return(true); }
public async Task <GetChargeStationDto> Handle(GetChargeStationQuery command, CancellationToken cancellationToken) { var chargeStation = await _stationRepository.GetAsync(command.Id).ConfigureAwait(false); if (chargeStation == null) { throw new ChargeStationNotFoundException(command.Id); } return(_mapper.Map <GetChargeStationDto>(chargeStation)); }
public async Task <UpdateChargeStationDto> Handle(UpdateChargeStationNameCommand command, CancellationToken cancellationToken) { var found = await _chargeStationRepository.ExistsAsync(command.Id).ConfigureAwait(false); if (!found) { throw new ChargeStationNotFoundException(command.Id); } await _chargeStationRepository.UpdateNameAsync(command.Id, command.Name).ConfigureAwait(false); var resource = await _chargeStationRepository.GetAsync(command.Id); return(_mapper.Map <UpdateChargeStationDto>(resource)); }