private void BtnDelete_Click(object sender, RoutedEventArgs e) { var CurrentBroker = brokerViewSource.View.CurrentItem as Broker; var broker = (from b in db.Brokers where b.BrokerID == CurrentBroker.BrokerID select b).SingleOrDefault(); if (broker != null) { string message = "Etes-vous sûr de vouloir supprimer ce courtier?"; string title = "Supprimer un courtier"; MessageBoxButton buttons = MessageBoxButton.YesNo; MessageBoxResult result = MessageBox.Show(message, title, buttons); if (result == MessageBoxResult.Yes) { db.Entry(broker).State = EntityState.Deleted; db.SaveChanges(); MessageBox.Show("Suppression terminé"); } else if (result == MessageBoxResult.No) { this.NavigationService.Navigate(new CustomersList()); } } }
private void BtnModify_Click(object sender, RoutedEventArgs e) { //On recupère l'objet avec l'ID actuel Appointment appointment = db.Appointments.Find(Convert.ToInt32(TxtAppointmentID.Text)); //Si l'objet est non nul, on créé un autre objet où on insère les modifications //puis on insère les modifications dans l'objet. if (appointment != null) { //Création de l'objet avec les infos modifiés var newAppointment = new Appointment() { AppointmentID = appointment.AppointmentID, BrokerID = Convert.ToInt32(BrokerComboBox.SelectedValue), CustomerID = Convert.ToInt32(CustomerComboBox.SelectedValue), Subject = TxtSubject.Text, DateHour = Convert.ToDateTime(dateHourDatePicker.Text) }; //On insere les données du nouvel objet dans l'ancien db.Entry(appointment).CurrentValues.SetValues(newAppointment); db.SaveChanges(); //On rafraichit le dataGrid. AppointmentsListDataGrid.ItemsSource = db.Appointments.ToList(); //On affiche une alerte afin d'informer la modification. MessageBox.Show("Le RDV a été modifié"); } }
private void BtnEnregistrerCustomer_Click(object sender, RoutedEventArgs e) { Customer customer = new Customer() { LastName = lastNameTextBox.Text, Firstname = firstnameTextBox.Text, PhoneNumber = phoneNumberTextBox.Text, Mail = mailTextBox.Text, Budget = decimal.Parse(budgetTextBox.Text) }; db.Entry(customer).State = EntityState.Added; db.SaveChanges(); }