public void SetupRace(string raceId, RaceSetupDto raceSetupDto) { if (string.IsNullOrEmpty(raceId)) { throw new ArgumentNullException("Missing RaceId"); } if (raceSetupDto == null) { throw new ArgumentNullException("Missing RaceSetup"); } if (raceSetupDto.Race == null) { throw new ArgumentNullException("Missing RaceSetup.Race"); } if (raceSetupDto.Disciplines == null) { throw new ArgumentNullException("Missing RaceSetup.Disciplines"); } if (raceSetupDto.ResultsLists == null) { throw new ArgumentNullException("Missing RaceSetup.ResultsLists"); } if (raceSetupDto.StartingLanes == null) { throw new ArgumentNullException("Missing RaceSetup.StartingLanes"); } IRepositorySet repositorySet = repositorySetProvider.GetRepositorySet(raceId); var raceSettings = VerifyRaceSettings(raceSetupDto.Race); var disciplineIds = new HashSet <string>(); var rulesNames = rulesProvider.GetNames(); var disciplines = new List <Discipline>(); foreach (var discipline in raceSetupDto.Disciplines) { disciplines.Add(VerifyDiscipline(discipline, disciplineIds, rulesNames)); } var startingLaneIds = new HashSet <string>(); var startingLanes = new List <StartingLane>(); foreach (var startingLane in raceSetupDto.StartingLanes) { startingLanes.Add(VerifyStartingLane(startingLane, disciplineIds)); } var resultsListsIds = new HashSet <string>(); var resultsLists = new List <ResultsList>(); foreach (var resultsList in raceSetupDto.ResultsLists) { resultsLists.Add(VerifyResultsList(resultsList, resultsListsIds, disciplineIds)); } var indexEntry = BuildIndexEntry(raceId, raceSettings); repositorySet.RaceSettings.SetRaceSettings(raceSettings); repositorySet.Disciplines.SetDisciplines(disciplines); repositorySet.StartingLanes.SetStartingLanes(startingLanes); repositorySet.ResultsLists.ClearResultLists(); foreach (var resultsList in resultsLists) { repositorySet.ResultsLists.SetResultsList(resultsList); } racesIndexRepository.SaveRace(indexEntry); }