/// <summary> /// Deprecated Method for adding a new object to the TeamLeagues EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTeamLeagues(TeamLeague teamLeague) { base.AddObject("TeamLeagues", teamLeague); }
void OnSaveChanges() { if (SelectedTeam == 0 || SelectedLeague == 0) { ShowDialog("Team and/or league are not selected"); return; } if (string.IsNullOrEmpty(SelectedYear)) { ShowDialog("The Year is not selected"); return; } var newTeamLeague = new TeamLeague { Year = Convert.ToInt16(SelectedYear), LeagueID = SelectedLeague, TeamID = SelectedTeam }; var existingContextTeam = _context.TeamLeagues.Where( t => (t.Year == newTeamLeague.Year) && (t.League.ID == newTeamLeague.LeagueID) && (t.Team.ID == newTeamLeague.TeamID)). Select(te => te).FirstOrDefault(); if (existingContextTeam != null) { return; } try { _context.TeamLeagues.Add(newTeamLeague); _context.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(string.Format("Error {0}", ex.Message)); } }
/// <summary> /// Create a new TeamLeague object. /// </summary> /// <param name="teamID">Initial value of the TeamID property.</param> /// <param name="leagueID">Initial value of the LeagueID property.</param> /// <param name="year">Initial value of the Year property.</param> public static TeamLeague CreateTeamLeague(global::System.Int32 teamID, global::System.Int32 leagueID, global::System.Int16 year) { TeamLeague teamLeague = new TeamLeague(); teamLeague.TeamID = teamID; teamLeague.LeagueID = leagueID; teamLeague.Year = year; return teamLeague; }