Two big refactorings done

This commit is contained in:
2020-04-15 21:51:58 +02:00
parent 8758ec170d
commit 1361fa048e
6 changed files with 54 additions and 66 deletions

View File

@ -9,18 +9,10 @@ namespace TrackerLibrary.DataAccess
{
public class TextConnector : IDataConnection
{
private const string PrizesFile = "PrizeModels.csv";
private const string PeopleFile = "PersonModels.csv";
private const string TeamFile = "TeamModels.csv";
private const string TournamentFile = "TournamentModels.csv";
private const string MatchupFile = "MatchupModels.csv";
private const string MatchupEntryFile = "MatchupEntryModels.csv";
public PersonModel CreatePerson(PersonModel model)
public void CreatePerson(PersonModel model)
{
List<PersonModel> people = PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();
List<PersonModel> people = GlobalConfig.PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();
int currentId = 1;
if (people.Count > 0)
@ -32,17 +24,15 @@ namespace TrackerLibrary.DataAccess
people.Add(model);
people.SaveToPeopleFile(PeopleFile);
return model;
people.SaveToPeopleFile();
}
// TODO - Wire up the createPrize for textFiles
public PrizeModel CreatePrize(PrizeModel model)
public void CreatePrize(PrizeModel model)
{
// Load the text file
// Convert the text to a List>PrizeModel>
List<PrizeModel> prizes = PrizesFile.FullFilePath().LoadFile().ConvertToPrizeModels();
List<PrizeModel> prizes = GlobalConfig.PrizesFile.FullFilePath().LoadFile().ConvertToPrizeModels();
// Find the max Id
@ -60,16 +50,15 @@ namespace TrackerLibrary.DataAccess
// Convert the prizes to a List<string>
// Save the list<String> to the text file
prizes.SaveToPrizeFile(PrizesFile);
prizes.SaveToPrizeFile();
return model;
}
public TeamModel CreateTeam(TeamModel model)
public void CreateTeam(TeamModel model)
{
// Load the text file
// Convert the text to a List>PrizeModel>
List<TeamModel> teams = TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);
List<TeamModel> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile().ConvertToTeamModels();
// Find the max Id
@ -89,26 +78,25 @@ namespace TrackerLibrary.DataAccess
// Convert the prizes to a List<string>
// Save the list<String> to the text file
teams.SaveToTeamFile(TeamFile);
teams.SaveToTeamFile();
return model;
}
public List<PersonModel> GetPerson_All()
{
return PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();
return GlobalConfig.PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();
}
public List<TeamModel> GetTeam_All()
{
return TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);
return GlobalConfig.TeamFile.FullFilePath().LoadFile().ConvertToTeamModels();
}
public void CreateTournament(TournamentModel model)
{
List<TournamentModel> tournaments = TournamentFile
List<TournamentModel> tournaments = GlobalConfig.TournamentFile
.FullFilePath()
.LoadFile()
.ConvertToTournamentModels(TeamFile, PeopleFile, PrizesFile);
.ConvertToTournamentModels();
int currentId = 1;
if (tournaments.Count > 0)
@ -117,19 +105,19 @@ namespace TrackerLibrary.DataAccess
}
model.Id = currentId;
model.SaveRoundsToFile( MatchupFile, MatchupEntryFile);
model.SaveRoundsToFile();
tournaments.Add(model);
tournaments.SaveToTournamentFile(TournamentFile);
tournaments.SaveToTournamentFile();
}
public List<TournamentModel> GetTournament_All()
{
return TournamentFile
return GlobalConfig.TournamentFile
.FullFilePath()
.LoadFile()
.ConvertToTournamentModels(TeamFile, PeopleFile, PrizesFile);
.ConvertToTournamentModels();
}
public void UpdateMatchup(MatchupModel model)