private void btnCreateCompetition_Click(object sender, EventArgs e) { AddCompetitionWizard wizard = new AddCompetitionWizard(); if (wizard.ShowDialog() == DialogResult.OK && wizard.Competition != null) { using (SVPEntitiesContainer context = new SVPEntitiesContainer()) { foreach (var price in wizard.Competition.Prices) { context.Profiles.Attach(price.Profile); } wizard.Competition.Date = DateTime.Now; context.Competitions.Add(wizard.Competition); context.SaveChanges(); currentCompetition = context.Competitions.Include("Prices.Profile").Where(x => x.Id == wizard.Competition.Id).FirstOrDefault(); } reload_Controls(); } }
private void btnEditCompetition_Click(object sender, EventArgs e) { AddCompetitionWizard wizard = new AddCompetitionWizard(this.currentCompetition); if (wizard.ShowDialog() == DialogResult.OK) { using (SVPEntitiesContainer context = new SVPEntitiesContainer()) { Competition c = context.Competitions.Find(wizard.Competition.Id); c.Name = wizard.Competition.Name; foreach (var price in wizard.Competition.Prices) { if (price.Id == 0) { c.Prices.Add(price); } else { Price p = context.Prices.Find(price.Id); p.Name = price.Name; p.Evaluation = p.Evaluation; } } foreach (Award award in wizard.Competition.Awards) { if (award.Id == 0) { c.Awards.Add(award); } else { Award a = context.Awards.Find(award.Id); a.Name = award.Name; } } context.SaveChanges(); } reload_Controls(); } }