Two big refactorings done
This commit is contained in:
@ -7,9 +7,9 @@ namespace TrackerLibrary.DataAccess
|
||||
{
|
||||
public interface IDataConnection
|
||||
{
|
||||
PrizeModel CreatePrize(PrizeModel model);
|
||||
PersonModel CreatePerson(PersonModel model);
|
||||
TeamModel CreateTeam(TeamModel model);
|
||||
void CreatePrize(PrizeModel model);
|
||||
void CreatePerson(PersonModel model);
|
||||
void CreateTeam(TeamModel model);
|
||||
void CreateTournament(TournamentModel model);
|
||||
void UpdateMatchup(MatchupModel model);
|
||||
List<TeamModel> GetTeam_All();
|
||||
|
||||
@ -18,7 +18,7 @@ namespace TrackerLibrary.DataAccess
|
||||
public class SqlConnector : IDataConnection
|
||||
{
|
||||
private const string db = "Tournaments";
|
||||
public PersonModel CreatePerson(PersonModel model)
|
||||
public void CreatePerson(PersonModel model)
|
||||
{
|
||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
||||
{
|
||||
@ -32,8 +32,6 @@ namespace TrackerLibrary.DataAccess
|
||||
connection.Execute("dbo.spPeople_Insert", p, commandType: CommandType.StoredProcedure);
|
||||
|
||||
model.Id = p.Get<int>("@Id");
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +41,7 @@ namespace TrackerLibrary.DataAccess
|
||||
/// </summary>
|
||||
/// <param name="model">The prize information.</param>
|
||||
/// <returns>The prize information, including the unique identifier.</returns>
|
||||
public Models.PrizeModel CreatePrize(Models.PrizeModel model)
|
||||
public void CreatePrize(Models.PrizeModel model)
|
||||
{
|
||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
||||
{
|
||||
@ -58,11 +56,10 @@ namespace TrackerLibrary.DataAccess
|
||||
|
||||
model.Id = p.Get<int>("@Id");
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
public TeamModel CreateTeam(TeamModel model)
|
||||
public void CreateTeam(TeamModel model)
|
||||
{
|
||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
||||
{
|
||||
@ -84,7 +81,6 @@ namespace TrackerLibrary.DataAccess
|
||||
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -7,6 +7,13 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TrackerLibrary.Models;
|
||||
|
||||
/*
|
||||
* Title :
|
||||
* Author :
|
||||
* Date :
|
||||
* Purpose:
|
||||
*/
|
||||
|
||||
namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
public static class TextConnectorProcessor
|
||||
@ -61,12 +68,12 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
return output;
|
||||
}
|
||||
|
||||
public static List<TeamModel> ConvertToTeamModels(this List<string> lines, string peopleFileName)
|
||||
public static List<TeamModel> ConvertToTeamModels(this List<string> lines)
|
||||
{
|
||||
// id, team name,list of ids separated by pipe
|
||||
// 3,Start Team, 1|4
|
||||
List<TeamModel> output = new List<TeamModel>();
|
||||
List<PersonModel> people = peopleFileName.FullFilePath().LoadFile().ConvertToPersonModels();
|
||||
List<PersonModel> people = GlobalConfig.PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
@ -91,10 +98,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
}
|
||||
|
||||
public static List<TournamentModel> ConvertToTournamentModels(
|
||||
this List<string> lines,
|
||||
string teamFileName,
|
||||
string peopleFileName,
|
||||
string prizesFileName
|
||||
this List<string> lines
|
||||
)
|
||||
{
|
||||
// id = 0
|
||||
@ -106,8 +110,8 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
|
||||
// id, TournamentName, EntryFee, (id|id|id - entered teams), (id|id|id - entered prizes), (rounds - id^id^id|id^id^id|id^id^id)
|
||||
List<TournamentModel> output = new List<TournamentModel>();
|
||||
List<TeamModel> teams = teamFileName.FullFilePath().LoadFile().ConvertToTeamModels(peopleFileName);
|
||||
List<PrizeModel> prizes = prizesFileName.FullFilePath().LoadFile().ConvertToPrizeModels();
|
||||
List<TeamModel> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile().ConvertToTeamModels();
|
||||
List<PrizeModel> prizes = GlobalConfig.PrizesFile.FullFilePath().LoadFile().ConvertToPrizeModels();
|
||||
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
|
||||
|
||||
foreach (string line in lines)
|
||||
@ -150,7 +154,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
return output;
|
||||
}
|
||||
|
||||
public static void SaveToPrizeFile(this List<PrizeModel> models, string fileName)
|
||||
public static void SaveToPrizeFile(this List<PrizeModel> models)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
@ -158,10 +162,10 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
lines.Add($"{p.Id},{p.PlaceNumber},{p.PlaceName}, {p.PrizeAmount}, {p.PrizePercentage}");
|
||||
}
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
File.WriteAllLines(GlobalConfig.PrizesFile.FullFilePath(), lines);
|
||||
}
|
||||
|
||||
public static void SaveToPeopleFile(this List<PersonModel> models, string fileName)
|
||||
public static void SaveToPeopleFile(this List<PersonModel> models)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
foreach (PersonModel p in models)
|
||||
@ -169,11 +173,11 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
lines.Add($"{p.Id},{p.FirstName},{p.LastName},{p.EmailAddress},{p.CellPhoneNumber}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
File.WriteAllLines(GlobalConfig.PeopleFile.FullFilePath(), lines);
|
||||
|
||||
}
|
||||
|
||||
public static void SaveToTeamFile(this List<TeamModel> models, string fileName)
|
||||
public static void SaveToTeamFile(this List<TeamModel> models)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
foreach (TeamModel t in models)
|
||||
@ -181,10 +185,10 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
lines.Add($"{t.Id},{t.TeamName},{ConvertPeopleListToString(t.TeamMembers)}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
File.WriteAllLines(GlobalConfig.TeamFile.FullFilePath(), lines);
|
||||
}
|
||||
|
||||
public static void SaveRoundsToFile(this TournamentModel model,string matchupFile,string matchupEntryFile)
|
||||
public static void SaveRoundsToFile(this TournamentModel model)
|
||||
{
|
||||
// Loop through each round
|
||||
// Loop through each matchup
|
||||
@ -198,7 +202,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
// Get the top id and add one
|
||||
// Store the id
|
||||
// Svae the matchup record
|
||||
matchup.SaveMatchupToFile(matchupFile, matchupEntryFile);
|
||||
matchup.SaveMatchupToFile();
|
||||
|
||||
|
||||
}
|
||||
@ -270,7 +274,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
List<string> matchingTeams = new List<string>();
|
||||
matchingTeams.Add(team);
|
||||
return matchingTeams.ConvertToTeamModels(GlobalConfig.PeopleFile).First();
|
||||
return matchingTeams.ConvertToTeamModels().First();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -318,7 +322,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
return output;
|
||||
}
|
||||
|
||||
public static void SaveMatchupToFile(this MatchupModel matchup, string matchupFile, string matchupEntryFile)
|
||||
public static void SaveMatchupToFile(this MatchupModel matchup)
|
||||
{
|
||||
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
|
||||
int currentId = 1;
|
||||
@ -332,7 +336,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
|
||||
foreach (MatchupEntryModel entry in matchup.Entries)
|
||||
{
|
||||
entry.SaveEntryToFile(matchupEntryFile);
|
||||
entry.SaveEntryToFile();
|
||||
}
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
@ -385,7 +389,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
File.WriteAllLines(GlobalConfig.MatchupFile.FullFilePath(), lines);
|
||||
}
|
||||
|
||||
public static void SaveEntryToFile(this MatchupEntryModel entry, string matchupEntryFile)
|
||||
public static void SaveEntryToFile(this MatchupEntryModel entry)
|
||||
{
|
||||
List<MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels();
|
||||
int currentId = 1;
|
||||
@ -452,7 +456,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
|
||||
}
|
||||
|
||||
public static void SaveToTournamentFile(this List<TournamentModel> models, string fileName)
|
||||
public static void SaveToTournamentFile(this List<TournamentModel> models)
|
||||
{
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
@ -461,7 +465,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
lines.Add($@"{tm.Id},{tm.TournamentName},{tm.EntryFee},{ConvertTeamListToString(tm.EnteredTeams)},{ConvertPrizeListToString(tm.Prizes)},{ConvertRoundListToString(tm.Rounds)}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
File.WriteAllLines(GlobalConfig.TournamentFile.FullFilePath(), lines);
|
||||
}
|
||||
|
||||
private static string ConvertRoundListToString(List<List<Models.MatchupModel>> rounds)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<!--<add key="filePath" value="D:\data\TournamentTracker"/>-->
|
||||
<add key="filePath" value="C:\AppData\TournamentTracker"/>
|
||||
<add key="filePath" value="D:\data\TournamentTracker"/>
|
||||
<!--<add key="filePath" value="C:\AppData\TournamentTracker"/>-->
|
||||
</appSettings>
|
||||
<connectionStrings>
|
||||
<add name="Tournaments" connectionString="Server=TOMMYASUS\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>
|
||||
<!--<add name="Tournaments" connectionString="Server=.\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>-->
|
||||
<!--<add name="Tournaments" connectionString="Server=TOMMYASUS\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>-->
|
||||
<add name="Tournaments" connectionString="Server=.\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>
|
||||
<!--Data Source=TOMMYASUS\SQLEXPR2017;Initial Catalog=Tournaments;Integrated Security=True-->
|
||||
</connectionStrings>
|
||||
<startup>
|
||||
|
||||
@ -19,7 +19,7 @@ namespace TrackerUI
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
// Initialize the database connections
|
||||
GlobalConfig.InitializeConnections(DatabaseType.Sql);
|
||||
GlobalConfig.InitializeConnections(DatabaseType.TextFile);
|
||||
Application.Run(new TournamentDashboardForm());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user