public AddQuestionListViewModel(LoginViewModel providerItem, QuestionListViewModel oldPage) { _oldPage = oldPage; dataServer = providerItem.dataServer; InspectionList = dataServer.GetInspecties(); CreateTemplate(); if (_oldPage.SelectedVragenlijst == null) { NewVragenlijst = new VragenlijstVM(""); NewVragenlijst.Vragen = new ObservableCollection <Vraag>(); AddVragenlijstCommand = new RelayCommand <AddQuestionListWindow>(AddVragenlijst); } else { NewVragenlijst = _oldPage.SelectedVragenlijst; NewVragenlijst.Vragen = new ObservableCollection <Vraag>(_oldPage.SelectedVragenlijst.Vragen); foreach (InspectieVM i in InspectionList) { if (i.Naam.Equals(_oldPage.SelectedVragenlijst.Inspectie.Naam)) { SelectedInspection = i; } } } // Command handlers SaveEditVragenlijstCommand = new RelayCommand <EditQuestionListWindow>(SaveEditVragenlijst); AddQuestionCommand = new RelayCommand <AddQuestionListWindow>(AddQuestionWindow); AddQuestionInEditCommand = new RelayCommand <EditQuestionListWindow>(AddQuestionInEditWindow); CancelAddCommand = new RelayCommand <AddQuestionListWindow>(CloseAddWindow); CancelEditCommand = new RelayCommand <EditQuestionListWindow>(CloseEditWindow); DeleteQuestionCommand = new RelayCommand(DeleteQuestion); }
private InspectieVM CreateTemplate() { //id of current user int GebruikerId = dataServer._gebruiker.Id; Klant klant = new Klant { Bedrijfsnaam = "Template bedrijf", Email = "*****@*****.**", Telefoonnummer = "0612345678", Postcode = "4581FJ", Huisnummer = 68 }; Offerte offerte = new Offerte { Prijs = 100.15, Toelichting = "Template offerte", Betaald = 0 }; Inspectie newInspectie = new Inspectie { RegistrantId = GebruikerId, Klant = klant, Status = new Status { Naam = "Geregistreerd" }, Offerte = offerte }; //does the offerte template already exist? int offertecount = dataServer.GetOfferte().Count(o => o.Toelichting.Equals("Template offerte")); //add offerte template to database if (offertecount == 0) { this.dataServer.AddOfferte(offerte); } //add template klant to database try { this.dataServer.AddKlant(klant); } catch (Exception e) { } //get id of TemplateKlant int templateKlantId = 0; var templateklant = dataServer.GetKlanten().Where(t => t.Bedrijfsnaam.Equals("Template bedrijf")); foreach (KlantVM t in templateklant) { templateKlantId = t.Id; } //get id of TemplateOfferte int templateOfferteId = 0; var templateOfferte = dataServer.GetOfferte().Where(o => o.Toelichting.Equals("Template offerte")); foreach (OfferteVM t in templateOfferte) { templateOfferteId = t.Id; } //set Id's for new inspectie newInspectie.Offerte.Id = templateOfferteId; newInspectie.OfferteId = templateOfferteId; newInspectie.Klant.Id = templateKlantId; newInspectie.KlantId = templateKlantId; //new inspection with template values InspectieVM inspectie = new InspectieVM(newInspectie) { Id = 0, Postcode = "5302XC", Datum = new DateTime(2019, 1, 1), StatusNaam = "Geregistreerd", Huisnummer = 52, Wens = "Het inspecteren van het festival", Inspecteur = new GebruikerVM { Id = GebruikerId, Naam = "Template", Achternaam = "van Festispec", Wachtwoord = "Template", Postcode = "5308LJ", Telefoonnummer = "0645781296", Huisnummer = 61, GeboorteDatum = new DateTime(1996, 1, 1), Email = "*****@*****.**", }, InspectieDatum = new DateTime(2019, 2, 1), Naam = "Template Inspectie" }; //does the template already exist? int templatecount = dataServer.GetInspecties().Count(i => i.Naam.Equals("Template Inspectie")); //add template to database if (templatecount == 0) { this.dataServer.AddInspection(inspectie); } return(inspectie); }