private void SaveAssignmentData() { _currentPeriod.assignments.Clear(); foreach (DataGridViewRow row in MatchRegime.Rows) { if (row.IsNewRow) { continue; } var newAss = new Assignment(); newAss.home = new Team { teamName = row.Cells["hometeam"].Value.ToString() }; newAss.guest = new Team { teamName = row.Cells["guestteam"].Value.ToString() }; newAss.field = new Field { fieldName = row.Cells["field"].Value.ToString() }; newAss.time = row.Cells["time"].Value?.ToString() ?? ""; newAss.referee = new Core.Referee { name = row.Cells["referee"].Value?.ToString() ?? "" }; newAss.helperA = new Core.Referee { name = row.Cells["refereeHelperA"].Value?.ToString() ?? "" }; newAss.helperB = new Core.Referee { name = row.Cells["refereeHelperB"].Value?.ToString() ?? "" }; newAss.watchRef = new WatchRef { name = row.Cells["refereeObserver"].Value?.ToString() ?? "" }; _currentPeriod.assignments.Add(newAss); } // For each saved period foreach (var p in ApplicationData.Periods) { // If our period exists in the data if (p.Equals(_currentPeriod)) { // update p's asssignments. p.assignments = _currentPeriod.assignments; ReloadAssignmentDataIntoGrid(); return; } } // Else just create it and add it to the data. ApplicationData.AddPeriod(_currentPeriod); ReloadAssignmentDataIntoGrid(); }