public static void CreateAccountNoEmailVerify(
            AsyncRPGDataContext context,
            string username,
            string clientHashedPassword,
            string emailAddress,
            DatabaseConstants.OpsLevel opsLevel)
        {
            // Then Salt and re-hash like the client password
            byte[] saltBytes      = null;
            string saltString     = CreateRandomSalt(out saltBytes);
            string saltedPassword = SaltAndHashPassword(clientHashedPassword, saltBytes);

            // Actually create an account entry in the database
            {
                Accounts account = new Accounts
                {
                    CreationDate         = DateTime.Now,
                    OpsLevel             = (int)opsLevel,
                    UserName             = username,
                    PasswordHash         = saltedPassword,
                    Salt                 = saltString,
                    EmailAddress         = emailAddress,
                    EmailVerificationKey = ""
                };

                context.Accounts.InsertOnSubmit(account);
                context.SubmitChanges();
            }
        }
        // Called directly by SetAccountOpsLevel web service call
        public static bool SetAccountOpsLevel(
            string connection_string,
            int account_id,
            DatabaseConstants.OpsLevel ops_level,
            out string result)
        {
            bool success = false;

            result = SuccessMessages.GENERAL_SUCCESS;

            using (AsyncRPGDataContext context = new AsyncRPGDataContext(connection_string))
            {
                try
                {
                    SetAccountOpsLevel(context, account_id, ops_level);
                    success = true;
                }
                catch (System.Exception)
                {
                    result = ErrorMessages.DB_ERROR + "(Failed to set account ops level)";
                }
            }

            return(success);
        }
        public static bool ValidateJSONRequestSessionHasAdminOpsLevel(
            ISessionAdapter session,
            out string error_code)
        {
            bool success            = true;
            int  session_account_id = GetSessionAccountID(session);

            DatabaseConstants.OpsLevel opsLevel =
                AccountQueries.GetAccountOpsLevel(
                    ApplicationConstants.CONNECTION_STRING,
                    session_account_id,
                    out error_code);

            if (opsLevel != DatabaseConstants.OpsLevel.invalid)
            {
                if (opsLevel >= DatabaseConstants.OpsLevel.admin)
                {
                    error_code = SuccessMessages.GENERAL_SUCCESS;
                    success    = true;
                }
                else
                {
                    error_code = ErrorMessages.INSUFFICIENT_OPS_LEVEL;
                }
            }

            return(success);
        }
        public static void SetAccountOpsLevel(
            AsyncRPGDataContext context,
            int account_id,
            DatabaseConstants.OpsLevel ops_level)
        {
            Accounts account = (from a in context.Accounts where a.AccountID == account_id select a).Single();

            account.OpsLevel = (int)ops_level;

            context.Accounts.InsertOnSubmit(account);
            context.SubmitChanges();
        }
        public static DatabaseConstants.OpsLevel GetAccountOpsLevel(
            string connection_string,
            int account_id,
            out string result)
        {
            DatabaseConstants.OpsLevel ops_level = DatabaseConstants.OpsLevel.invalid;

            result = SuccessMessages.GENERAL_SUCCESS;

            using (AsyncRPGDataContext context = new AsyncRPGDataContext(connection_string))
            {
                try
                {
                    ops_level = GetAccountOpsLevel(context, account_id);
                }
                catch (System.Exception)
                {
                    result = ErrorMessages.DB_ERROR + "(Failed to get account ops level)";
                }
            }

            return(ops_level);
        }