Exemplo n.º 1
0
        public Boolean LoadFromDatabase(Application application, Mercury.Server.Data.SqlDatabase environmentDatabase, String roleName)
        {
            String criteria;

            criteria = "WHERE RoleName = '" + roleName + "'";

            return(LoadFromDatabaseWithCriteria(application, environmentDatabase, criteria));
        }
Exemplo n.º 2
0
        public Boolean LoadFromDatabase(Application application, Mercury.Server.Data.SqlDatabase environmentDatabase, Int64 roleId)
        {
            String criteria;

            criteria = "WHERE RoleId = " + roleId;

            return(LoadFromDatabaseWithCriteria(application, environmentDatabase, criteria));
        }
Exemplo n.º 3
0
        public Boolean LoadFromDatabaseWithCriteria(Application application, Mercury.Server.Data.SqlDatabase environmentDatabase, String criteria)
        {
            Boolean success = false;

            StringBuilder selectStatement = new StringBuilder();

            System.Data.DataTable tableEnvironment;

            selectStatement.Append("SELECT * FROM Role " + criteria);

            tableEnvironment = environmentDatabase.SelectDataTable(selectStatement.ToString());

            if (tableEnvironment.Rows.Count == 1)
            {
                MapDataFields(tableEnvironment.Rows[0]);

                success = true;
            }

            return(success);
        }
Exemplo n.º 4
0
        } // MapDataFields (System.Data.DataRow currentRow)

        public Boolean Save(Mercury.Server.Data.SqlDatabase environmentDatabase)
        {
            Boolean success = false;

            StringBuilder sqlStatement = new StringBuilder();


            try {
                environmentDatabase.BeginTransaction();

                sqlStatement.Append("EXEC Role_InsertUpdate ");

                sqlStatement.Append(RoleId.ToString() + ", '" + roleName.Replace("'", "''") + "', '" + description.Replace("'", "''") + "', ");

                sqlStatement.Append("'" + modifiedAccountInfo.SecurityAuthorityNameSql + "', '" + modifiedAccountInfo.UserAccountIdSql + "', '" + modifiedAccountInfo.UserAccountNameSql + "'");

                success = environmentDatabase.ExecuteSqlStatement(sqlStatement.ToString());

                if ((success) && (roleId == 0))
                {
                    try {
                        Object identity = environmentDatabase.ExecuteScalar("SELECT @@IDENTITY").ToString();

                        if (identity != null)
                        {
                            roleId = Int64.Parse(identity.ToString());
                        }
                    }

                    catch {
                        success = false;
                    }
                }

                if (success)
                {
                    success = success && environmentDatabase.ExecuteSqlStatement("DELETE FROM RolePermission WHERE RoleId = " + roleId.ToString());

                    success = success && environmentDatabase.ExecuteSqlStatement("DELETE FROM RoleMembership WHERE RoleId = " + roleId.ToString());


                    foreach (RolePermission currentPermission in permissions)
                    {
                        currentPermission.RoleId = roleId;

                        currentPermission.ModifiedAccountInfo = modifiedAccountInfo;

                        success = success && currentPermission.Save(environmentDatabase);
                    }

                    foreach (RoleMembership currentMembership in membership)
                    {
                        currentMembership.RoleId = roleId;

                        currentMembership.ModifiedAccountInfo = modifiedAccountInfo;

                        success = success && currentMembership.Save(environmentDatabase);
                    }
                }

                if (success)
                {
                    environmentDatabase.CommitTransaction();
                }

                else
                {
                    throw new ApplicationException((environmentDatabase.LastException != null) ? environmentDatabase.LastException.Message : "Unable to Save Environment Role");
                }
            }

            catch (Exception saveException) {
                System.Diagnostics.Debug.WriteLine("Unable to Save: " + saveException.Message);

                success = false;

                environmentDatabase.RollbackTransaction();
            }

            return(success);
        }