Before implementing save to textfiles
This commit is contained in:
@ -10,6 +10,7 @@ namespace TrackerLibrary.DataAccess
|
||||
PrizeModel CreatePrize(PrizeModel model);
|
||||
PersonModel CreatePerson(PersonModel model);
|
||||
TeamModel CreateTeam(TeamModel model);
|
||||
TournamentModel CreateTournament(TournamentModel model);
|
||||
List<TeamModel> GetTeam_All();
|
||||
List<PersonModel> GetPerson_All();
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ namespace TrackerLibrary.DataAccess
|
||||
|
||||
model.Id = p.Get<int>("@Id");
|
||||
|
||||
foreach(PersonModel tm in model.TeamMembers)
|
||||
foreach (PersonModel tm in model.TeamMembers)
|
||||
{
|
||||
p = new DynamicParameters();
|
||||
p.Add("@TeamId", model.Id);
|
||||
@ -89,6 +89,65 @@ namespace TrackerLibrary.DataAccess
|
||||
|
||||
}
|
||||
|
||||
public TournamentModel CreateTournament(TournamentModel model)
|
||||
{
|
||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
||||
{
|
||||
DynamicParameters p = SaveTournament(model, connection);
|
||||
|
||||
p = SaveTournamentPrizes(model, connection, p);
|
||||
|
||||
p = SaveTournamentEntries(model, connection, p);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
private static DynamicParameters SaveTournament(TournamentModel model, IDbConnection connection)
|
||||
{
|
||||
var p = new DynamicParameters();
|
||||
p.Add("@TournamentName", model.TournamentName);
|
||||
p.Add("@EntryFee", model.EntryFee);
|
||||
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
||||
|
||||
connection.Execute("dbo.spTournaments_Insert", p, commandType: CommandType.StoredProcedure);
|
||||
|
||||
model.Id = p.Get<int>("@Id");
|
||||
return p;
|
||||
}
|
||||
|
||||
private static DynamicParameters SaveTournamentEntries(TournamentModel model, IDbConnection connection, DynamicParameters p)
|
||||
{
|
||||
foreach (TeamModel tm in model.EnteredTeams)
|
||||
{
|
||||
p = new DynamicParameters();
|
||||
p.Add("@TournamentId", model.Id);
|
||||
p.Add("@TeamId", tm.Id);
|
||||
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
||||
|
||||
connection.Execute("dbo.spTournamentEntries_Insert", p, commandType: CommandType.StoredProcedure);
|
||||
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private static DynamicParameters SaveTournamentPrizes(TournamentModel model, IDbConnection connection, DynamicParameters p)
|
||||
{
|
||||
foreach (PrizeModel pz in model.Prizes)
|
||||
{
|
||||
p = new DynamicParameters();
|
||||
p.Add("@TournamentId", model.Id);
|
||||
p.Add("@PrizeId", pz.Id);
|
||||
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
||||
|
||||
connection.Execute("dbo.spTournamentPrizes_Insert", p, commandType: CommandType.StoredProcedure);
|
||||
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public List<PersonModel> GetPerson_All()
|
||||
{
|
||||
|
||||
@ -107,11 +166,11 @@ namespace TrackerLibrary.DataAccess
|
||||
{
|
||||
output = connection.Query<TeamModel>("dbo.spTeam_GetAll").ToList();
|
||||
|
||||
foreach(TeamModel team in output)
|
||||
foreach (TeamModel team in output)
|
||||
{
|
||||
var p = new DynamicParameters();
|
||||
p.Add("@TeamId", team.Id);
|
||||
team.TeamMembers = connection.Query<PersonModel>("dbo.spTeamMembers_GetByTeam",p, commandType: CommandType.StoredProcedure).ToList();
|
||||
team.TeamMembers = connection.Query<PersonModel>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
|
||||
}
|
||||
}
|
||||
return output;
|
||||
|
||||
@ -12,6 +12,8 @@ namespace TrackerLibrary.DataAccess
|
||||
private const string PrizesFile = "PrizeModels.csv";
|
||||
private const string PeopleFile = "PersonModels.csv";
|
||||
private const string TeamFile = "TeamModels.csv";
|
||||
private const string TournamentFile = "TournamentModels.csv";
|
||||
|
||||
|
||||
public PersonModel CreatePerson(PersonModel model)
|
||||
{
|
||||
@ -98,5 +100,10 @@ namespace TrackerLibrary.DataAccess
|
||||
{
|
||||
return TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);
|
||||
}
|
||||
public TournamentModel CreateTournament(TournamentModel model)
|
||||
{
|
||||
List<TournamentModel> tournaments = TournamentFile.FullFilePath().LoadFile().ConvertToTournamentModels();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,9 +90,12 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
return output;
|
||||
}
|
||||
|
||||
public static List<TournamentModel> ConvertToTournamentModels(this List<string> lines)
|
||||
{
|
||||
// id, TournamentName, EntryFee, (id|id|id - entered teams), (id|id|id - entered prizes), (rounds - id^id^id|id^id^id|id^id^id)
|
||||
}
|
||||
|
||||
|
||||
public static void SaveToPrizeFile(this List<PrizeModel> models, string fileName)
|
||||
public static void SaveToPrizeFile(this List<PrizeModel> models, string fileName)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
|
||||
@ -6,10 +6,29 @@ namespace TrackerLibrary.Models
|
||||
{
|
||||
public class TournamentModel
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for this tournament
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// The name given to this tournament
|
||||
/// </summary>
|
||||
public string TournamentName { get; set; }
|
||||
/// <summary>
|
||||
/// The amount of money each team needs to put up to enter
|
||||
/// </summary>
|
||||
public decimal EntryFee { get; set; }
|
||||
/// <summary>
|
||||
/// The set of teams that have entered
|
||||
/// </summary>
|
||||
public List<Models.TeamModel> EnteredTeams { get; set; } = new List<Models.TeamModel>();
|
||||
/// <summary>
|
||||
/// The list of prizes for various places
|
||||
/// </summary>
|
||||
public List<Models.PrizeModel> Prizes { get; set; } = new List<Models.PrizeModel>();
|
||||
public List<List<Models.MatchupModel>> MyProperty { get; set; } = new List<List<Models.MatchupModel>>();
|
||||
/// <summary>
|
||||
/// The matchups per round
|
||||
/// </summary>
|
||||
public List<List<Models.MatchupModel>> Rounds { get; set; } = new List<List<Models.MatchupModel>>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user