public void AddCar(Car car) { if (car == null) { throw new ArgumentNullException(String.Format("Input '{0}' argumet was null!", nameof(car))); } if (!CarsList.Any(c => c.Id == car.Id)) { CarsList.Add(car); } else { throw new ArgumentException(String.Format("The parking already contains a car with '{0}' description! Choose another one and try again!", car.Id)); } }
public void RemoveCar(Car car) { if (car == null) { throw new ArgumentNullException(String.Format("Input '{0}' argument was null!", nameof(car))); } if (CarsList.Any(c => c.Id == car.Id)) { if (car.Balance > 0) { CarsList.Remove(car); } else { throw new InvalidOperationException("This car's balance is less than 0. Please, top up an account and try again!"); } } else { throw new ArgumentException("There no such car on the parking!"); } }