/// <inheritdoc />
        public void StartRentalByScooterId(string scooterId)
        {
            var scooter = _scooterRepository.GetById(scooterId);

            if (scooter == null)
            {
                throw new ScooterNotFoundException(scooterId);
            }

            if (scooter.IsRented)
            {
                throw new InvalidScooterOperationException(scooterId);
            }

            var previousRental = _rentalRepository.GetLastRentalByScooterId(scooterId);

            if (previousRental != null && !previousRental.RentalEnd.HasValue)
            {
                throw new InvalidScooterOperationException(scooterId);
            }

            scooter.IsRented = true;
            var rental = new Rental
            {
                ScooterId   = scooterId,
                RentalStart = DateTime.UtcNow,
                RentalEnd   = null
            };

            _rentalRepository.CreateOrUpdate(rental);
            _scooterRepository.CreateOrUpdate(scooter);
        }
Example #2
0
        /// <inheritdoc />
        public void AddScooter(string id, decimal pricePerMinute)
        {
            var scooter = _scooterRepository.GetById(id);

            if (scooter != null)
            {
                throw new DuplicateScooterException(id);
            }

            scooter = new Scooter(id, pricePerMinute);

            _scooterRepository.CreateOrUpdate(scooter);
        }
 public Scooter GetScooterById(int id)
 {
     return(_scooterRepository.GetById(id));
 }