bool IHost.Delete(Theme theme) { if (KryptonMessageBox.Show(this, Strings.QuestionDeleteTheme, Strings.DeleteTheme, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Account user = SelectUserDialog.Get(this); if (user == null) { return(false); } using (ISession session = DataHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { session.Delete(theme); transaction.Commit(); return(true); } catch (ADOException e) { transaction.Rollback(); Trace.TraceError(ErrorHelper.Message(e)); ErrorHelper.ShowDbError(this, e); return(false); } } } } return(false); }
bool IHost.Open(Theme theme) { user = SelectUserDialog.Get(this); if (user != null) { currentTheme = theme; Text = $"{Strings.VocabularyTest} - {theme.Name}"; LoadWindowLayout(); addons.Run(); using (ISession session = DataHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { currentTheme.AccessDate = DateTime.Now; session.SaveOrUpdate(currentTheme); transaction.Commit(); backgroundLoading.RunWorkerAsync(new DictionaryProperty(dictionaries, theme.Languages.ToList())); return(true); } catch (ADOException e) { transaction.Rollback(); Trace.TraceError(ErrorHelper.Message(e)); ErrorHelper.ShowDbError(this, e); return(false); } } } } return(false); }
bool IHost.Create() { currentTheme = ThemeDialog.Create(this); if (currentTheme != null) { user = SelectUserDialog.Get(this); if (user != null) { Text = $"{Strings.VocabularyTest} - {currentTheme.Name}"; LoadWindowLayout(); addons.Run(); return(true); } } return(false); }
public static Account Get(IWin32Window owner) { bool admin = Environment.GetCommandLineArgs().Contains("/admin"); using (ISession session = DataHelper.OpenSession()) { Repository <Account> repo = new Repository <Account>(session); IEnumerable <Account> users = from Account account in repo.All().List() where account.Role == account_role.user || (account.Role == account_role.administrator && admin) select account; if (users.FirstOrDefault() == null) { return(null); } SelectUserDialog dialog = null; if (users.Count() > 1) { dialog = new SelectUserDialog(users, null); } else { Account user = users.First(); dialog = new SelectUserDialog(users, user); /*if (!string.IsNullOrEmpty(user.Password)) * { * dialog = new SelectUserDialog(users, user); * } * else * { * return user; * }*/ } if (dialog != null && dialog.ShowDialog(owner) == DialogResult.OK) { return(dialog.comboUsers.SelectedItem as Account); } } return(null); }