예제 #1
0
        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);
        }
예제 #2
0
        public async Task <bool> Handle(DeleteChargeGroupCommand command, CancellationToken cancellationToken)
        {
            var group = await _groupRepository.GetAsyncExtended(command.Id).ConfigureAwait(false);

            if (group == null)
            {
                throw new ChargeGroupNotFoundException(command.Id);
            }

            foreach (var station in group.ChargeStations)
            {
                await _stationRepository.DeleteAsync(station.Id).ConfigureAwait(false);
            }
            await _groupRepository.DeleteAsync(command.Id).ConfigureAwait(false);

            return(true);
        }