public string AddRacer(string type, string username, string carVIN) { Racer racer = null; var car = this.cars.FindBy(carVIN); if (car == null) { throw new ArgumentException(CarCannotBeFound); } if (type == "ProfessionalRacer") { racer = new ProfessionalRacer(username, car); } else if (type == "StreetRacer") { racer = new StreetRacer(username, car); } else { throw new ArgumentException(InvalidRacerType); } this.racers.Add(racer); return(string.Format(SuccessfullyAddedRacer, username)); }
public string AddRacer(string type, string username, string carVIN) { Racer racer = default; ICar car = cars.FindBy(carVIN); if (car == null) { throw new ArgumentException(ExceptionMessages.CarCannotBeFound); } if (type == nameof(ProfessionalRacer)) { racer = new ProfessionalRacer(username, car); } else if (type == nameof(StreetRacer)) { racer = new StreetRacer(username, car); } else { throw new ArgumentException(ExceptionMessages.InvalidRacerType); } racers.Add(racer); return(string.Format(OutputMessages.SuccessfullyAddedRacer, username)); }
public string AddRacer(string type, string username, string carVIN) { if (type != "ProfessionalRacer" && type != "StreetRacer") { throw new ArgumentException(ExceptionMessages.InvalidRacerType); } IRacer racer = null; ICar car = carRepository.FindBy(carVIN); if (car == null) { throw new ArgumentException(ExceptionMessages.CarCannotBeFound); } if (type == "ProfessionalRacer") { racer = new ProfessionalRacer(username, car); } else if (type == "StreetRacer") { racer = new StreetRacer(username, car); } this.racerRepository.Add(racer); return(string.Format(OutputMessages.SuccessfullyAddedRacer, username)); }
public string AddRacer(string type, string username, string carVIN) { IRacer currentRaces = null; ICar currentCar = cars.FindBy(carVIN); if (currentCar == null) { throw new ArgumentException("Car cannot be found!"); } if (type == "ProfessionalRacer") { currentRaces = new ProfessionalRacer(username, currentCar); racers.Add(currentRaces); return($"Successfully added racer {username}."); } else if (type == "StreetRacer") { currentRaces = new StreetRacer(username, currentCar); racers.Add(currentRaces); return($"Successfully added racer {username}."); } else { throw new ArgumentException("Invalid racer type!"); } }
public string AddRacer(string type, string username, string carVIN) { ICar car = cars.FindBy(carVIN); if (car is null) { throw new ArgumentException(ExceptionMessages.CarCannotBeFound); } IRacer racer; switch (type) { case "ProfessionalRacer": racer = new ProfessionalRacer(username, car); break; case "StreetRacer": racer = new StreetRacer(username, car); break; default: throw new ArgumentException(ExceptionMessages.InvalidRacerType); } racers.Add(racer); return(string.Format(OutputMessages.SuccessfullyAddedRacer, username)); }
public string AddRacer(string type, string username, string carVIN) { var carRacer = this.cars.FindBy(carVIN); string result; if (carRacer == null) { throw new ArgumentException("Car cannot be found"); } if (type == "ProfessionalRacer") { IRacer racer = new ProfessionalRacer(username, carRacer); this.racers.Add(racer); result = $"Successfully added racer {username}."; } else if (type == "StreetRacer") { IRacer racer = new ProfessionalRacer(username, carRacer); this.racers.Add(racer); result = $"Successfully added racer {username}."; } else { throw new ArgumentException("Invalid racer type"); } return(result); }
public string AddRacer(string type, string username, string carVIN) { ICar car = this.cars.FindBy(carVIN); if (car == null) { throw new ArgumentException("Car cannot be found!"); } if (type != nameof(ProfessionalRacer) && type != nameof(StreetRacer)) { throw new ArgumentException("Invalid racer type!"); } IRacer racer; if (type == nameof(ProfessionalRacer)) { racer = new ProfessionalRacer(username, car); } else { racer = new StreetRacer(username, car); } this.racers.Add(racer); return(string.Format(OutputMessages.SuccessfullyAddedRacer, racer.Username)); }
public string AddRacer(string type, string username, string carVIN) { bool success = false; foreach (var model in cars.Models) { if (model.VIN == carVIN) { success = true; } } if (success == false) { throw new ArgumentException(ExceptionMessages.CarCannotBeFound); } if (type != "ProfessionalRacer" && type != "StreetRacer") { throw new ArgumentException(ExceptionMessages.InvalidRacerType); } if (type == "ProfessionalRacer") { var car = cars.Models.FirstOrDefault(x => x.VIN == carVIN); ProfessionalRacer professionalRacer = new ProfessionalRacer(username, car); } else if (type == "StreetRacer") { var car = cars.Models.FirstOrDefault(x => x.VIN == carVIN); StreetRacer professionalRacer = new StreetRacer(username, car); } return($"Successfully added racer {username}."); }