private void buttonSave_Click(object sender, EventArgs e) { ReceptionSelection selectedRec = (ReceptionSelection)comboBoxReception.SelectedItem; GetMenu_Result selectedMenu; if (selectedRec != null) { try { using (ProjetSGBDEntities context = new ProjetSGBDEntities()) { context.NewReservation(selectedRec.Id, CurrentClient.Id, CurrentClient.Acronym); if (dataGridViewDessert.SelectedRows.Count == 1) { selectedMenu = (GetMenu_Result)dataGridViewDessert.SelectedRows[0].DataBoundItem; context.NewReservedDish(CurrentClient.Id, selectedMenu.DishId, selectedRec.Id, CurrentClient.Acronym); } if (dataGridViewMainCourse.SelectedRows.Count == 1) { selectedMenu = (GetMenu_Result)dataGridViewMainCourse.SelectedRows[0].DataBoundItem; context.NewReservedDish(CurrentClient.Id, selectedMenu.DishId, selectedRec.Id, CurrentClient.Acronym); } if (dataGridViewStarter.SelectedRows.Count == 1) { selectedMenu = (GetMenu_Result)dataGridViewStarter.SelectedRows[0].DataBoundItem; context.NewReservedDish(CurrentClient.Id, selectedMenu.DishId, selectedRec.Id, CurrentClient.Acronym); } } Close(); } catch (Exception ex) { ModelError modelError = new ModelError(ex); MessageBox.Show(modelError.Message, "Erreur fatale!", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; } } }