private void AddMedicamentsEntities1(Prescription prescription) { var medicament = new Medicament() { //IdMedicament = 1, Name = "Paracetamol", Type = "Pill", Description = "Headache" }; var mediacamentPrescription = new MedicamentPrescription() { Medicament = medicament, Prescription = prescription, Dose = 20, Details = "Obligatory" }; Medicaments.Add(medicament); MedicamentPrescriptions.Add(mediacamentPrescription); }
private void AddMedicamentsEntities2(Prescription prescription) { var medicament = new Medicament() { //IdMedicament = 2, Name = "Eurespal", Type = "Liquid", Description = "Throat treatment" }; var mediacamentPrescription = new MedicamentPrescription() { Medicament = medicament, Prescription = prescription, Dose = 10, Details = "Not necessary" }; Medicaments.Add(medicament); MedicamentPrescriptions.Add(mediacamentPrescription); }
public MedicamentViewModel() { DownloadMedicaments(); EditMedicament = new DelegateCommand(() => { editoradd = false; selectedMedicament?.BeginEdit(); var w = new MedicamentEdit(); w.DataContext = this; w.ShowDialog(); }, () => selectedMedicament != null); AddMedicament = new DelegateCommand(() => { editoradd = true; Medicament medicament = new Medicament(); SelectedMedicament = medicament; var w = new MedicamentEdit(); w.DataContext = this; w.ShowDialog(); }); SaveMedicament = new DelegateCommand(() => { if (editoradd == true) { context.Medicament.Add(selectedMedicament); context.SaveChanges(); Medicaments.Add(SelectedMedicament); } else { context.Entry(SelectedMedicament).State = EntityState.Modified; context.SaveChanges(); } }); RemoveMedicament = new DelegateCommand(() => { if (MessageBox.Show("Удалить?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { context.Entry(selectedMedicament).State = EntityState.Deleted; context.SaveChanges(); Medicaments.Remove(selectedMedicament); } else { return; } }, () => selectedMedicament != null); CanselEdit = new DelegateCommand(() => { if (editoradd == false) { if (selectedMedicament == null) { return; } SelectedMedicament.CancelEdit(); } else { return; } }); }