public async Task LendBike(Bike bike)
        {
            if (bike.HasLock)
            {
                if (!await _lockService.OpenLock(bike))
                {
                    return;
                }
            }

            bike.CurrentUser   = _userId;
            bike.Location      = null;
            bike.ReservedUntil = null;

            if (bike.StationId != null)
            {
                var station = await _stationRepository.Get(bike.CommunityId, bike.StationId);

                bike.StationId = null;

                await _context.RunTransactionAsync(transaction =>
                {
                    _stationRepository.Update(station, nameof(Station.NumberOfBikes), FieldValue.Increment(-1), transaction);
                    _bikeRepository.Update(bike, transaction);
                });

                return;
            }

            await _bikeRepository.Update(bike);
        }
Esempio n. 2
0
 private Task EndBreak(Bike bike) => _lockService.OpenLock(bike);