ClimberOnCompetition ProcessAppearance(Person person, ClimbingStyles styles, int?bib, ClimberQf qf, String ageGroupId, Competition comp) { if (person.CompetitionAppearances == null) { person.CompetitionAppearances = new List <ClimberOnCompetition>(); } var app = person.CompetitionAppearances.FirstOrDefault(c => c.CompId == comp.Iid); bool isNew = true; if (app == null) { person.CompetitionAppearances.Add(app = new ClimberOnCompetition(Context) { Competition = comp, CompId = comp.Iid, Person = person, PersonId = person.Iid, Teams = new List <ClimberTeamOnCompetition>() }); } else { isNew = false; } app.AgeGroupId = ageGroupId; app.Qf = qf; app.SecretaryBib = bib; app.Styles = styles; Context.SaveChanges(); return(Context.ClimbersOnCompetition.First(c => c.Iid == app.Iid)); }
ClimberTeamOnCompetition ProcessLicenseOnCompetition(ClimberOnCompetition climber, Climber license) { if (climber.Teams == null) { climber.Teams = new List <ClimberTeamOnCompetition>(); } var res = climber.Teams.FirstOrDefault(t => t.TeamLicenseId == license.Iid); if (res != null) { return(res); } climber.Teams.Add(res = new ClimberTeamOnCompetition(Context) { Climber = climber, TeamLicense = license, TeamLicenseId = license.Iid, TeamOrder = climber.Teams.Count + 1 }); Context.SaveChanges(); return(Context.ClimberTeamsOnCompetition.First(c => c.Iid == res.Iid)); }