public string AddRiderToRace(string raceName, string riderName) { IRace race = raceRepository.GetByName(raceName); IRider rider = riderRepository.GetByName(riderName); race.AddRider(rider); return($"{string.Format(OutputMessages.RiderAdded, riderName, raceName)}"); }
public string AddRiderToRace(string raceName, string riderName) { IRace race = races.GetByName(raceName); IRider rider = riders.GetByName(riderName); race.AddRider(rider); return(string.Format(OutputMessages.RiderAdded, rider.Name, race.Name)); } // TODO: Repair
public string CreateRace(string name, int laps) { IRace race = new Race(name, laps); if (raceRepository.GetByName(name) != null) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceExists, name)); } raceRepository.Add(race); return(String.Format(OutputMessages.RaceCreated, name)); }
public string AddRiderToRace(string raceName, string riderName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } else if (riderRepository.GetByName(riderName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RiderNotFound, riderName)); } else if (raceRepository.GetByName(raceName).Riders.Any(r => r.Name == riderName)) { throw new InvalidOperationException(string.Format(ExceptionMessages.RiderAlreadyAdded, riderName, raceName)); } else if (riderRepository.GetByName(riderName).Motorcycle == null) { throw new InvalidOperationException(string.Format(string.Format(ExceptionMessages.RiderNotParticipate, riderName))); } else { raceRepository.GetByName(raceName).AddRider(riderRepository.GetByName(riderName)); return(string.Format(OutputMessages.RiderAdded, riderName, raceName)); } }
public string CreateRace(string name, int laps) { var race = raceRepository.GetByName(name); if (race != null) { throw new InvalidOperationException($"Race {name} is already created."); } race = new Race(name, laps); raceRepository.Add(race); var result = $"Race {name} is created."; return(result); }
public string AddDriverToRace(string raceName, string driverName) { IRace currentRace = raceRep.GetByName(raceName); IDriver currentDriver = driveRep.GetByName(driverName); if (currentRace == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (currentDriver == null) { throw new InvalidOperationException($"Driver {driverName} could not be found."); } currentRace.AddDriver(currentDriver); return($"Driver {driverName} added in {raceName} race."); }
public string AddRiderToRace(string raceName, string riderName) { if (raceRepository.GetByName(riderName) == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (riderRepository.GetByName(riderName) == null) { throw new InvalidOperationException($"Rider {riderName} could not be found."); } var r = raceRepository.GetByName(raceName); var rider = riderRepository.GetByName(riderName); r.AddRider(rider); return($"Rider {riderName} added in {raceName} race."); }
public string AddRiderToRace(string raceName, string riderName) { var targetRace = raceRepo.GetByName(raceName); var targetRider = riderRepo.GetByName(riderName); if (targetRace == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (targetRider == null) { throw new InvalidOperationException($"Rider {riderName} could not be found."); } targetRace.AddRider(targetRider); return($"Rider {targetRider.Name} added in {targetRace.Name} race."); }
public string AddRiderToRace(string raceName, string riderName) { IRider rider = riderRepository.Riders.FirstOrDefault(x => x.Name == riderName); IRace race = raceRepository.GetByName(raceName); if (rider == null) { throw new InvalidOperationException($"Rider {riderName} could not be found."); } if (race == null) { throw new InvalidOperationException($"Race { raceName } could not be found."); } race.AddRider(rider); return($"Rider {riderName} added in {raceName} race."); }
public string AddRiderToRace(string raceName, string riderName) { var race = raceRepository.GetByName(raceName); var rider = riderRepository.GetByName(riderName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (rider == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RiderNotFound, riderName)); } race.AddRider(rider); return(string.Format(OutputMessages.RiderAdded, riderName, raceName)); }
public string AddDriverToRace(string raceName, string driverName) { IRace raceResult = raceRepository.GetByName(raceName); IDriver driverResult = driverRepository.GetByName(driverName); if (raceResult == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (driverResult == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.DriverNotFound, driverName)); } raceResult.AddDriver(driverResult); return($"{string.Format(OutputMessages.DriverAdded, driverName, raceName)}"); }
public string AddDriverToRace(string raceName, string driverName) { var race = raceRepository.GetByName(raceName); if (race == null) { throw new ArgumentException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } var driver = driverRepository.GetByName(driverName); if (driver == null) { throw new ArgumentException(string.Format(ExceptionMessages.DriverNotFound, driverName)); } race.AddDriver(driver); return(string.Format(OutputMessages.DriverAdded, driverName, raceName)); }
public string AddDriverToRace(string raceName, string driverName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (driverRepository.GetByName(driverName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.DriverNotFound, driverName)); } //raceRepository.GetByName(raceName).AddDriver(driverRepository.GetByName(driverName)); driver = driverRepository.GetByName(driverName); race = raceRepository.GetByName(raceName); race.AddDriver(driver); return(string.Format(OutputMessages.DriverAdded, driverName, raceName)); }
public string CreateRace(string name, int laps) { var raceRepo = raceRepository.GetByName(name); if (raceRepo != null) { throw new InvalidOperationException($"Race {name} is already created."); } IRace race = new Race(name); this.raceRepository.Add(race); return($"Race {name} is created."); }
public string StartRace(string raceName) { var race = raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } var firstTree = race.Riders.OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)).Take(3).ToList(); if (firstTree.Count <= 2) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } StringBuilder sb = new StringBuilder(); sb.AppendLine($"Rider {firstTree[0].Name} wins {raceName} race."); sb.AppendLine($"Rider {firstTree[1].Name} is second in {raceName} race."); sb.AppendLine($"Rider {firstTree[2].Name} is third in {raceName} race."); raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }