private void createIndigene() { ISessionFactory sessionFactory = DataBaseConnection.CreateSessionFactory(); using (ISession session = sessionFactory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { Indigene indigene = null; try { indigene = new Indigene { FirstName = name.Text.Substring(0, name.Text.IndexOf(" ")).Trim(), OtherNames = name.Text.Substring(name.Text.IndexOf(" ")).Trim(), Village = village.SelectedItem.ToString().Trim(), MaritalStatus = maritalstatus.SelectedItem.ToString().Trim(), Sex = sexComboBox.SelectedItem.ToString().Trim(), DateOfBirth = (DateTime)dateofbirthDatePicker.SelectedDate, NameOfParents = nameofParents.Text.Trim(), Occupation = occupation.Text.Trim(), PhoneNumber = phoneNumber.Text.Trim(), PlaceOfResidence = placeofResidence.Text.Trim(), Comments = comments.Text.Trim() }; }catch (Exception e) { parentWindow.ShowDialog("Some fields are empty, please fill them and then re-submit", true); return; } ValidationHelper validationHelper = new ValidationHelper(indigene); if (!validationHelper.IsValid) { parentWindow.ShowDialog(validationHelper.Message(), true); } else { foreach (var child in childList) { indigene.AddChild(child); session.Save(child); } session.Save(indigene); transaction.Commit(); parentWindow.ShowDialog("new Indigene created", true); parentWindow.IndigeneUpdate(); } } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { indigeneListCache = new List <Indigene>(); if (!dataLoaded) { TaskFactory tf = new TaskFactory(); tf.StartNew(() => { this.Dispatcher.Invoke((Action)(() => { loadData(); parentWindow.HideDialog(); })); }); parentWindow.setHeaderTitle(controlTitle); parentWindow.ShowDialog("Loading data...", false); } indigeneEditForm = new IndigeneEditFormControl(parentWindow, this); }