/// <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); }
/// <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)); }