Esempio n. 1
0
        public void SaveAdministrators(SmartCollection<User> admins)
        {
            if (admins == null) return;

            if (this.hostSettings != null) {
                if (hostSettings.ValidateModel()) {
                    using (HostDAO dao = new HostDAO()) {
                        dao.SaveHostSettings(this.hostSettings);
                        AppVars.dbSettings = hostSettings;
                    }
                }
            }

            try {
                int result = -1;
                string sql;
                using (HostDAO dao = new HostDAO()) {
                    this.HostSettings = new SMHostSettings(dao.GetHostSettings());
                    AppVars.dbSettings = hostSettings;

                }
                using (SystemDAO systemDao = new SystemDAO()) {
                    using (systemDao.DbConnection = new MsSqlPersistence(systemDao.DbConnectionSettings)) {
                        if (systemDao.DbConnection.IsConnected()) {
                            using (systemDao.DbCommand) {
                                foreach (User user in admins) {
                                    systemDao.DbCommand.CommandType = System.Data.CommandType.StoredProcedure;
                                    systemDao.DbCommand.Parameters.Clear();
                                    if (user.UserId <= 0 || user.UserId == null) {
                                        systemDao.DbCommand.CommandText = "uspInsertAdministrator";
                                        string hashedPassword = Security.GetSha2Hash(user.Password.Trim(), user.Username.Trim());
                                        systemDao.DbCommand.Parameters.AddWithValue("@Password", hashedPassword);
                                    }else {
                                        systemDao.DbCommand.CommandText = "uspUpdateAdministrator";
                                        systemDao.DbCommand.Parameters.AddWithValue("@UserId", user.UserId);
                                    }
                                    systemDao.DbCommand.Parameters.AddWithValue("@Username", user.Username);
                                    systemDao.DbCommand.Parameters.AddWithValue("@FirstName", user.FirstName);
                                    systemDao.DbCommand.Parameters.AddWithValue("@LastName", user.LastName);
                                    systemDao.DbCommand.Parameters.AddWithValue("@AdministratorYN", true);
                                    string administratorKey = Security.GetSha2Hash(user.Username, hostSettings.BaseKey);
                                    systemDao.DbCommand.Parameters.AddWithValue("@AdministratorKey", administratorKey);
                                    if (user.UserId <= 0 || user.UserId == null) {
                                        result = (int)systemDao.DbConnection.ExecuteCommand(systemDao.DbCommand);
                                    }else result = systemDao.DbConnection.ExecuteCommand(systemDao.DbCommand);
                                }
                            }
                        }else {
                            throw new Exception("Unable to Connect");
                        }
                    }
                }
            }catch {
                throw ;
            }
        }
Esempio n. 2
0
 public void ShowAdmins()
 {
     if (DbCurrenVersion == 0)
     {
         if (this.hostSettings != null)
         {
             if (hostSettings.ValidateModel())
             {
                 using (HostDAO dao = new HostDAO())
                 {
                     dao.SaveHostSettings(this.hostSettings);
                 }
             }
         }
         ServiceHost.Implementation.Init.GetSettings();
         using (DataBaseDao dao = new DataBaseDao())
         {
             this.DbCurrenVersion = dao.GetDatabaseVersion();
         }
     }
     if (ServiceHost.Update.Init.Update(DbCurrenVersion))
         CurrentView = ManagerViews.Admins;
 }
Esempio n. 3
0
        public void Save()
        {
            if (this.hostSettings != null) {
                if (hostSettings.ValidateModel()) {
                    using (HostDAO dao = new HostDAO()) {
                        dao.SaveHostSettings(this.hostSettings);
                        AppVars.dbSettings = hostSettings;
                    }
                }
            }

            if (this.hostOptions != null) {
                if (HostOptions.Validate(hostOptions)) {
                    using (HostDAO dao = new HostDAO()) {
                        dao.SaveHostOptions(this.hostOptions);
                    }
                }
            }

            if (this.accountingSettings != null)
            {
                using (HostDAO dao = new HostDAO())
                {
                    dao.SaveAccountingSettings(this.AccountingSettings);
                }
            }

            SaveAdministrators(adminList);

            if (DbCurrenVersion == 0)
            {
                ServiceHost.Implementation.Init.GetSettings();
                using (DataBaseDao dao = new DataBaseDao())
                {
                    this.DbCurrenVersion = dao.GetDatabaseVersion();
                }

                ServiceHost.Update.Init.Update(DbCurrenVersion);
            }
            Environment.Exit(1);
        }