public IHttpActionResult DeleteRace(int?id) { if (!id.HasValue) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var raceDB = raceRepository.GetRace(id ?? (int)InvalidPropertyValues.undefinedValue); if (raceDB == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var tickets = ticketRepository.GetTicketsByRace(raceDB.RaceID); if (tickets.Any()) { return(BadRequest("The Race is used in a Ticket!\nTo delete it contact your Database Manager.")); } foreach (var item in raceDB.Assets) { fileManager.DeleteFile(item); filePathRepository.RemoveFilepath(item.FilePath); } fileManager.DeleteFolders(ModelType.Race, raceDB.RaceID.ToString()); raceRepository.Remove(raceDB); unitOfWork.Complete(); return(Ok()); }
public string StartRace(string raceName) { IRace race = raceRepository.Models.FirstOrDefault(r => r.Name == raceName); if (race == null) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Riders.Count < 3) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } riders = race.Riders.ToList(); Ordering(r => r.Motorcycle.CalculateRacePoints(race.Laps)); string first = riders.First().Name; string sec = riders.Skip(1).First().Name; string third = riders.Skip(2).First().Name; StringBuilder sb = new StringBuilder(); sb.AppendLine(String.Format(OutputMessages.RiderFirstPosition, first, race.Name)) .AppendLine(String.Format(OutputMessages.RiderSecondPosition, sec, race.Name)) .AppendLine(String.Format(OutputMessages.RiderThirdPosition, third, race.Name)); raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { IRace race = raceRepository.Models.FirstOrDefault(r => r.Name == raceName); if (race is null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Riders.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } List <IRider> orderedRaceRep = race.Riders.OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)).ToList(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 2; i++) { orderedRaceRep[i].WinRace(); } sb.AppendLine($"Rider {orderedRaceRep[0].Name} wins {raceName} race."); sb.AppendLine($"Rider {orderedRaceRep[1].Name} is second in {raceName} race."); sb.AppendLine($"Rider {orderedRaceRep[2].Name} is third in {raceName} race."); raceRepository.Remove(race); return(sb.ToString().Trim()); }
public string StartRace(string raceName) { if (races.GetAll().All(r => r.Name != raceName)) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceNotFound, raceName)); } IRace race = races.GetAll().First(r => r.Name == raceName); if (race.Riders.Count < 3) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } List <IRider> winners = race.Riders.OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)).Take(3).ToList(); //Forgotten winners[0].WinRace(); StringBuilder result = new StringBuilder(); result.AppendLine(String.Format(OutputMessages.RiderFirstPosition, winners[0].Name, race.Name)) .AppendLine(String.Format(OutputMessages.RiderSecondPosition, winners[1].Name, race.Name)) .AppendLine(String.Format(OutputMessages.RiderThirdPosition, winners[2].Name, race.Name)); //Forgotten races.Remove(race); return(result.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceNotFound, raceName)); } if (driverRepository.GetAll().Count < 3) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } IRace race = raceRepository.GetByName(raceName); List <IDriver> fastest = race.Drivers.OrderByDescending(x => x.Car.CalculateRacePoints(race.Laps)).ToList(); StringBuilder sb = new StringBuilder(); sb.AppendLine($"Driver {fastest[0].Name} wins {race.Name} race."); sb.AppendLine($"Driver {fastest[1].Name} is second in {race.Name} race."); sb.AppendLine($"Driver {fastest[2].Name} is third in {race.Name} race."); raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } Race currentrace = (Race)raceRepository.Races.First(x => x.Name == raceName); if (currentrace.Riders.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } var result = currentrace.Riders .OrderByDescending(x => x.Motorcycle.CalculateRacePoints(currentrace.Laps)) .Take(3).ToArray(); StringBuilder sb = new StringBuilder(); sb.AppendLine($"Rider {result[0].Name} wins {currentrace.Name} race."); sb.AppendLine($"Rider {result[1].Name} is second in {currentrace.Name} race."); sb.AppendLine($"Rider {result[2].Name} is third in {currentrace.Name} race."); raceRepository.Remove(currentrace); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { var race = raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Drivers.Count() < MinRaceParticipants) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, MinRaceParticipants)); } var drivers = race.Drivers.OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)) .Take(3) .ToArray(); var winner = drivers[0]; winner.WinRace(); raceRepository.Remove(race); string ret = string.Format(OutputMessages.DriverFirstPosition, winner.Name, raceName) + Environment.NewLine + string.Format(OutputMessages.DriverSecondPosition, drivers[1].Name, raceName) + Environment.NewLine + string.Format(OutputMessages.DriverThirdPosition, drivers[2].Name, raceName); return(ret); }
public string StartRace(string raceName) { IRace currentRace = raceRep.GetByName(raceName); if (currentRace == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (currentRace.Drivers.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } var drivers = currentRace.Drivers .OrderByDescending(x => x.Car.CalculateRacePoints(currentRace.Laps)).ToList(); var first = drivers[0]; var second = drivers[1]; var third = drivers[2]; StringBuilder result = new StringBuilder(); result.AppendLine($"Driver {first.Name} wins {currentRace.Name} race."); result.AppendLine($"Driver {second.Name} is second in {currentRace.Name} race."); result.Append($"Driver {third.Name} is third in {currentRace.Name} race."); raceRep.Remove(currentRace); return(result.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } IRace race = raceRepository.GetByName(raceName); if (race.Drivers.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } List <IDriver> orderedDrivers = race.Drivers.OrderByDescending(x => x.Car.CalculateRacePoints(race.Laps)).Take(3).ToList(); raceRepository.Remove(race); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format(OutputMessages.DriverFirstPosition, orderedDrivers[0].Name, raceName)); sb.AppendLine(string.Format(OutputMessages.DriverSecondPosition, orderedDrivers[1].Name, raceName)); sb.AppendLine(string.Format(OutputMessages.DriverThirdPosition, orderedDrivers[2].Name, raceName)); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (races.GetByName(raceName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (races.GetByName(raceName).Riders.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } else { var race = races.GetByName(raceName); var laps = race.Laps; var firstThreeRiders = race.Riders .OrderByDescending(r => r.Motorcycle.CalculateRacePoints(laps)) .Take(3) .ToArray(); races.Remove(race); return(string.Format(OutputMessages.RiderFirstPosition, firstThreeRiders[0].Name, raceName) + Environment.NewLine + string.Format(OutputMessages.RiderSecondPosition, firstThreeRiders[1].Name, raceName) + Environment.NewLine + string.Format(OutputMessages.RiderThirdPosition, firstThreeRiders[2].Name, raceName)); } }
public string StartRace(string raceName) { IRace race = raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (race.Drivers.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } IReadOnlyCollection <IDriver> drivers = driverRepository.GetAll(); drivers = drivers.OrderByDescending(x => x.Car.CalculateRacePoints(race.Laps)).ToList(); Console.WriteLine($"Driver {drivers.First().Name} wins {raceName} race."); Console.WriteLine($"Driver {drivers.Skip(1).First().Name} is second in {raceName} race."); Console.WriteLine($"Driver {drivers.Skip(2).First().Name} is third in {raceName} race."); raceRepository.Remove(race); return($"Driver {drivers.First().Name} wins {raceName} race." + Environment.NewLine + $"Driver {drivers.Skip(1).First().Name} is second in {raceName} race." + Environment.NewLine + $"Driver {drivers.Skip(2).First().Name} is third in {raceName} race."); }
public string StartRace(string raceName) { var race = this.raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (race.Drivers.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } var drivers = race.Drivers.OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).ToList(); //this.driverRepository.GetAll().OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).ToList(); var first = drivers[0]; var second = drivers[1]; var third = drivers[2]; StringBuilder sb = new StringBuilder(); sb.AppendLine($"Driver {first.Name} wins {raceName} race."); sb.AppendLine($"Driver {second.Name} is second in {raceName} race."); sb.AppendLine($"Driver {third.Name} is third in {raceName} race."); raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { var race = raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (race.Riders.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } var fastestRiders = race.Riders .OrderByDescending(x => x.Motorcycle.CalculateRacePoints(race.Laps)) .Take(3) .ToList(); var sb = new StringBuilder(); sb.AppendLine($"Rider {fastestRiders[0].Name} wins {raceName} race."); sb.AppendLine($"Rider {fastestRiders[1].Name} is second in {raceName} race."); sb.AppendLine($"Rider {fastestRiders[2].Name} is third in {raceName} race."); raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } IRace race = raceRepository.GetByName(raceName); List <IRider> bestRiders = race.Riders.OrderByDescending(x => x.Motorcycle.CalculateRacePoints(raceRepository.GetByName(raceName).Laps)).ToList(); if (bestRiders.Count() < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } StringBuilder sb = new StringBuilder(); sb.AppendLine($"Rider {bestRiders.ElementAt(0).Name} wins {raceRepository.GetByName(raceName).Name} race.") .AppendLine($"Rider {bestRiders.ElementAt(1).Name} is second in {raceRepository.GetByName(raceName).Name} race.") .AppendLine($"Rider {bestRiders.ElementAt(2).Name} is third in {raceRepository.GetByName(raceName).Name} race."); raceRepository.Remove(raceRepository.GetByName(raceName)); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { var existRace = this.raceRepository.Models.FirstOrDefault(x => x.Name == raceName); if (existRace == null) { throw new InvalidOperationException(String.Format(ExceptionMessages.RiderNotFound, raceName)); } if (existRace.Riders.Count < MIN_PARTICIPANTS) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceInvalid, raceName, MIN_PARTICIPANTS)); } var winners = riderRepository.Models.OrderByDescending(x => x.Motorcycle.CalculateRacePoints(existRace.Laps)).ToList(); var firstplace = winners[0].Name; var secondPlace = winners[1].Name; var thirdPlace = winners[2].Name; raceRepository.Remove(existRace); var sb = new StringBuilder(); sb.AppendLine($"Rider {firstplace} wins {raceName} race."); sb.AppendLine($"Rider {secondPlace} is second in {raceName} race."); sb.AppendLine($"Rider {thirdPlace} is third in {raceName} race."); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { var race = raceRepository.Models.FirstOrDefault(x => x.Name == raceName); if (!raceRepository.Models.Any(x => x.Name == raceName)) { throw new InvalidOperationException($"Race {raceName} could not be found."); } else if (race.Riders == null || race.Riders.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } //race.Riders.OrderByDescending(x => x.Motorcycle.CalculateRacePoints(race.Laps)); var wins = new Rider(string.Empty); var second = new Rider(string.Empty); var third = new Rider(string.Empty); foreach (Rider rider in race.Riders) { if (rider.Motorcycle.CalculateRacePoints(race.Laps) > wins.Motorcycle.CalculateRacePoints(race.Laps)) { wins = rider; } else if (rider.Motorcycle.CalculateRacePoints(race.Laps) > second.Motorcycle.CalculateRacePoints(race.Laps)) { second = rider; } else if (rider.Motorcycle.CalculateRacePoints(race.Laps) > third.Motorcycle.CalculateRacePoints(race.Laps)) { third = rider; } } string result = $"Rider {wins.Name} wins {raceName} race." + Environment.NewLine + $"Rider {second.Name} is second in {raceName} race." + Environment.NewLine + $"Rider {third.Name} is third in {raceName} race."; raceRepository.Remove(race); return(result); }
public string StartRace(string raceName) { if (!races.GetAll().Any(x => x.Name == raceName)) { string msg = string.Format(ExceptionMessages.RaceNotFound, raceName); throw new InvalidOperationException(msg); } IRace race = races.GetAll().FirstOrDefault(x => x.Name == raceName); if (race.Drivers.Count < minPartisipants) { string msg = string.Format(ExceptionMessages.RaceInvalid, raceName, minPartisipants); throw new InvalidOperationException(msg); } int laps = race.Laps; var fastestDrivers = race.Drivers.OrderByDescending(x => x.Car.CalculateRacePoints(laps)).Take(3).ToList(); int count = 1; StringBuilder sb = new StringBuilder(); foreach (var driver in fastestDrivers) { if (count == 1) { sb.AppendLine($"Driver {driver.Name} wins {race.Name} race."); } else if (count == 2) { sb.AppendLine($"Driver {driver.Name} is second in {race.Name} race."); } else if (count == 3) { sb.AppendLine($"Driver {driver.Name} is third in {race.Name} race."); } count++; } races.Remove(race); return(sb.ToString().Trim()); }
public string StartRace(string raceName) { if (raceRepository.GetAll().All(x => x.Name != raceName)) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } var race = raceRepository.GetByName(raceName); if (race.Riders.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } int i = 0; var sb = new StringBuilder(); foreach (var rider in race.Riders.OrderByDescending(x => x.Motorcycle.CalculateRacePoints(race.Laps))) { if (i == 0) { sb.AppendLine(string.Format(OutputMessages.RiderFirstPosition, rider.Name, race.Name)); } if (i == 1) { sb.AppendLine(string.Format(OutputMessages.RiderSecondPosition, rider.Name, race.Name)); } if (i == 2) { sb.AppendLine(string.Format(OutputMessages.RiderThirdPosition, rider.Name, race.Name)); break; } Console.WriteLine(rider.Name); i++; } raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (!races.GetAll().Any(x => x.Name == raceName)) { throw new InvalidOperationException($"Race {raceName} could not be found."); } IRace race = this.races.GetAll().FirstOrDefault(r => r.Name == raceName); if (race.Drivers.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } List <IDriver> driversInRace = race.Drivers.ToList().OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).Take(3).ToList(); StringBuilder result = new StringBuilder(); for (int i = 0; i < driversInRace.Count; i++) { IDriver driver = driversInRace[i]; if (i == 0) { result.AppendLine($"Driver {driver.Name} wins {raceName} race."); } else if (i == 1) { result.AppendLine($"Driver {driver.Name} is second in {raceName} race."); } else if (i == 2) { result.AppendLine($"Driver {driver.Name} is third in {raceName} race."); } } races.Remove(race); return(result.ToString().Trim()); }
public IHttpActionResult HardDeleteRaceClassification(int?id) { if (!User.IsInRole(AvailableRoles.DatabaseManager)) { return(BadRequest("You have not access to delete the race classification.\nPlease contact your Database Manager.")); } //The HardDeleteRaceClassification Action will remove every record in database that relates with the race classification if (!id.HasValue) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var raceClassificationDB = raceClassificationRepository.GetRaceClassification(id ?? (int)InvalidPropertyValues.undefinedValue); if (raceClassificationDB == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var races = raceRepository.GetRacesForClassifications(raceClassificationDB.RaceClassificationID); var racesIds = races.Select(r => r.RaceID); var tickets = ticketRepository.GetTicketsByRace(racesIds.ToArray()); ClearOrders(tickets); ticketRepository.RemoveMultipleTicket(tickets); foreach (var race in races) { ClearAssets(race); raceRepository.Remove(race); } raceClassificationRepository.Remove(raceClassificationDB); unitOfWork.Complete(); return(Ok()); }
public string StartRace(string raceName) { if (raceRepo.GetByName(raceName) == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } var targetRace = raceRepo.GetByName(raceName); if (targetRace.Riders.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } var bestThreeRiders = targetRace.Riders.OrderByDescending(x => x.Motorcycle.CalculateRacePoints(targetRace.Laps)).Take(3); var sb = new StringBuilder(); int counter = 0; raceRepo.Remove(targetRace); foreach (var rider in bestThreeRiders) { if (counter == 0) { sb.AppendLine($"Rider {rider.Name} wins {raceName} race."); rider.WinRace(); } else if (counter == 1) { sb.AppendLine($"Rider {rider.Name} is second in {raceName} race."); } else if (counter == 2) { sb.AppendLine($"Rider {rider.Name} is third in {raceName} race."); } counter++; } return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { IRace race = RaceRepository.Colection.FirstOrDefault(el => el.Name == raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Drivers.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } List <IDriver> driversRanking = race.Drivers.Where(el => el.CanParticipate == true) .OrderByDescending(el => el.Car.CalculateRacePoints(race.Laps)).ToList(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format(OutputMessages.DriverFirstPosition, driversRanking[0].Name, raceName)); sb.AppendLine(string.Format(OutputMessages.DriverSecondPosition, driversRanking[1].Name, raceName)); sb.AppendLine(string.Format(OutputMessages.DriverThirdPosition, driversRanking[2].Name, raceName)); RaceRepository.Remove(race); return(sb.ToString().Trim()); }