public static List <TourmanentModel> ConvertToTournamentModel(this List <string> Lines, string teamFileName, string peopleFileName, string prizeFileName) { //id, torunament name, entryFee, (id|id|id - Entered Teams), (id|id|id - Prizes), (Rounds - id^id^id|id^id^id|id^id^id) List <TourmanentModel> output = new List <TourmanentModel>(); List <TeamModel> teams = teamFileName.FullFilePath().LoadFile().ConvertToTeamModels(peopleFileName); List <PrizeModel> prizes = prizeFileName.FullFilePath().LoadFile().ConvertToPrizeModel(); foreach (string line in Lines) { string[] cols = line.Split(','); TourmanentModel tm = new TourmanentModel(); tm.Id = int.Parse(cols[0]); tm.TournamentName = cols[1]; tm.EntryFee = decimal.Parse(cols[2]); string[] teamIds = cols[3].Split('|'); foreach (string id in teamIds) { tm.EnteredTeams.Add(teams.Where(x => x.Id == int.Parse(id)).First()); } string[] prizeIds = cols[4].Split('|'); foreach (string id in prizeIds) { tm.Prizes.Add(prizes.Where(x => x.Id == int.Parse(id)).First()); } //TODO - Capture Rounds Information output.Add(tm); } return(output); }
private void CreateTournamentButton_Click(object sender, EventArgs e) { //Validate data for fee entry bool feeAcceptable = decimal.TryParse(entryFeeValue.Text, out decimal fee); if (!feeAcceptable) { MessageBox.Show("You need to enter a valid Entry Fee", "Invalid Fee", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Create our tournament model TourmanentModel tm = new TourmanentModel(); tm.TournamentName = tournamentNameValue.Text; tm.EntryFee = fee; tm.Prizes = selectedPrizes; tm.EnteredTeams = selectedTeams; //Create our matchups //Create the Tournament Entry //Create all of the prizes entries //Create all of the team entries GlobalConfig.Connection.CreateTournament(tm); }
public void CreateTournament(TourmanentModel model) { using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString(db))) { SaveTournament(connection, model); SaveTournamentPrizes(connection, model); SaveTournamentEntries(connection, model); //return model; } }
private void SaveTournamentEntries(IDbConnection connection, TourmanentModel model) { foreach (TeamModel tm in model.EnteredTeams) { var p = new DynamicParameters(); p.Add("@TournamentId", model.Id); p.Add("@TeamId", tm.Id); p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); /// /// Executre SQL Database Stored Procedure: spTournamentEntries_Insert /// connection.Execute("dbo.spTournamentEntries_Insert", p, commandType: CommandType.StoredProcedure); } }
/// <summary> /// PRIVATE METHODS... /// </summary> /// <param name="model"></param> private void SaveTournament(IDbConnection connection, TourmanentModel model) { var p = new DynamicParameters(); p.Add("@TournamentName", model.TournamentName); p.Add("@EntryFee", model.EntryFee); p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); /// /// Executre SQL Database Stored Procedure: spTournaments_Insert /// connection.Execute("dbo.spTournaments_Insert", p, commandType: CommandType.StoredProcedure); /// Get the the id value back that will be generated by SQL database model.Id = p.Get <int>("@id"); }
public void CreateTournament(TourmanentModel model) { List <TourmanentModel> tourmanents = TournamentFile. FullFilePath(). LoadFile(). ConvertToTournamentModel(TeamFile, PeopleFile, PrizesFile); int currentId = 1; if (tourmanents.Count > 0) { currentId = tourmanents.OrderByDescending(x => x.Id).First().Id + 1; } model.Id = currentId; tourmanents.Add(model); tourmanents.SaveToTournamentFile(TournamentFile); }