Esempio n. 1
0
        private int ResetUserState(ResetUserStateMode mode, DateTime userInactiveSinceDate, string[] paths, string[] usernames)
        {
            var connection = new MySQLPersonalizationConnectionHelper(connectionString);

            connection.OpenConnection(true);

            try
            {
                if (ResetUserStateMode.PerInactiveDate == mode)
                {
                    return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate.ToUniversalTime(), null, null, connection));
                }
                if (ResetUserStateMode.PerPaths == mode)
                {
                    return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate, null, paths, connection));
                }
                else
                {
                    return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate, usernames, paths, connection));
                }
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - ResetUserState");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }
        private int ResetUserState(ResetUserStateMode mode,
                                   DateTime userInactiveSinceDate,
                                   string[] paths,
                                   string[] usernames) {
            SqlConnectionHolder connectionHolder = null;
            SqlConnection connection = null;
            int count = 0;

            // Extra try-catch block to prevent elevation of privilege attack via exception filter
            try {
                bool beginTranCalled = false;
                try {
                    connectionHolder = GetConnectionHolder();
                    connection = connectionHolder.Connection;
                    Debug.Assert(connection != null);

                    CheckSchemaVersion( connection );

                    SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_ResetUserState", connection);
                    SetCommandTypeAndTimeout(command);
                    SqlParameterCollection parameters = command.Parameters;

                    SqlParameter parameter = parameters.Add(new SqlParameter("Count", SqlDbType.Int));
                    parameter.Direction = ParameterDirection.Output;

                    parameters.AddWithValue("ApplicationName", ApplicationName);

                    string firstPath = (paths != null && paths.Length > 0) ? paths[0] : null;

                    if (mode == ResetUserStateMode.PerInactiveDate) {
                        if (userInactiveSinceDate != PersonalizationAdministration.DefaultInactiveSinceDate) {
                            // Special note: DateTime object cannot be added to collection
                            // via AddWithValue for some reason.
                            parameter = parameters.Add("InactiveSinceDate", SqlDbType.DateTime);
                            parameter.Value = userInactiveSinceDate.ToUniversalTime();
                        }

                        if (firstPath != null) {
                            parameters.AddWithValue("Path", firstPath);
                        }

                        command.ExecuteNonQuery();
                        SqlParameter countParam = command.Parameters[0];
                        if (countParam != null && countParam.Value != null && countParam.Value is Int32) {
                            count = (Int32) countParam.Value;
                        }
                    }
                    else if (mode == ResetUserStateMode.PerPaths) {
                        Debug.Assert(paths != null);
                        parameter = parameters.Add("Path", SqlDbType.NVarChar);
                        foreach (string path in paths) {
                            if (!beginTranCalled && paths.Length > 1) {
                                (new SqlCommand("BEGIN TRANSACTION", connection)).ExecuteNonQuery();
                                beginTranCalled = true;
                            }

                            parameter.Value = path;
                            command.ExecuteNonQuery();
                            SqlParameter countParam = command.Parameters[0];
                            if (countParam != null && countParam.Value != null && countParam.Value is Int32) {
                                count += (Int32) countParam.Value;
                            }
                        }
                    }
                    else {
                        Debug.Assert(mode == ResetUserStateMode.PerUsers);
                        if (firstPath != null) {
                            parameters.AddWithValue("Path", firstPath);
                        }

                        parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                        foreach (string user in usernames) {
                            if (!beginTranCalled && usernames.Length > 1) {
                                (new SqlCommand("BEGIN TRANSACTION", connection)).ExecuteNonQuery();
                                beginTranCalled = true;
                            }

                            parameter.Value = user;
                            command.ExecuteNonQuery();
                            SqlParameter countParam = command.Parameters[0];
                            if (countParam != null && countParam.Value != null && countParam.Value is Int32) {
                                count += (Int32) countParam.Value;
                            }
                        }
                    }

                    if (beginTranCalled) {
                        (new SqlCommand("COMMIT TRANSACTION", connection)).ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                }
                catch {
                    if (beginTranCalled) {
                        (new SqlCommand("ROLLBACK TRANSACTION", connection)).ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                    throw;
                }
                finally {
                    if (connectionHolder != null) {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }

            return count;
        }
Esempio n. 3
0
        private int ResetUserState(ResetUserStateMode mode,
                                   DateTime userInactiveSinceDate,
                                   string[] paths,
                                   string[] usernames)
        {
            SqlConnectionHolder connectionHolder = null;
            SqlConnection       connection       = null;
            int count = 0;

            // Extra try-catch block to prevent elevation of privilege attack via exception filter
            try {
                bool beginTranCalled = false;
                try {
                    connectionHolder = GetConnectionHolder();
                    connection       = connectionHolder.Connection;
                    Debug.Assert(connection != null);

                    CheckSchemaVersion(connection);

                    SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_ResetUserState", connection);
                    SetCommandTypeAndTimeout(command);
                    SqlParameterCollection parameters = command.Parameters;

                    SqlParameter parameter = parameters.Add(new SqlParameter("Count", SqlDbType.Int));
                    parameter.Direction = ParameterDirection.Output;

                    parameters.AddWithValue("ApplicationName", ApplicationName);

                    string firstPath = (paths != null && paths.Length > 0) ? paths[0] : null;

                    if (mode == ResetUserStateMode.PerInactiveDate)
                    {
                        if (userInactiveSinceDate != PersonalizationAdministration.DefaultInactiveSinceDate)
                        {
                            // Special note: DateTime object cannot be added to collection
                            // via AddWithValue for some reason.
                            parameter       = parameters.Add("InactiveSinceDate", SqlDbType.DateTime);
                            parameter.Value = userInactiveSinceDate.ToUniversalTime();
                        }

                        if (firstPath != null)
                        {
                            parameters.AddWithValue("Path", firstPath);
                        }

                        command.ExecuteNonQuery();
                        SqlParameter countParam = command.Parameters[0];
                        if (countParam != null && countParam.Value != null && countParam.Value is Int32)
                        {
                            count = (Int32)countParam.Value;
                        }
                    }
                    else if (mode == ResetUserStateMode.PerPaths)
                    {
                        Debug.Assert(paths != null);
                        parameter = parameters.Add("Path", SqlDbType.NVarChar);
                        foreach (string path in paths)
                        {
                            if (!beginTranCalled && paths.Length > 1)
                            {
                                (new SqlCommand("BEGIN TRANSACTION", connection)).ExecuteNonQuery();
                                beginTranCalled = true;
                            }

                            parameter.Value = path;
                            command.ExecuteNonQuery();
                            SqlParameter countParam = command.Parameters[0];
                            if (countParam != null && countParam.Value != null && countParam.Value is Int32)
                            {
                                count += (Int32)countParam.Value;
                            }
                        }
                    }
                    else
                    {
                        Debug.Assert(mode == ResetUserStateMode.PerUsers);
                        if (firstPath != null)
                        {
                            parameters.AddWithValue("Path", firstPath);
                        }

                        parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                        foreach (string user in usernames)
                        {
                            if (!beginTranCalled && usernames.Length > 1)
                            {
                                (new SqlCommand("BEGIN TRANSACTION", connection)).ExecuteNonQuery();
                                beginTranCalled = true;
                            }

                            parameter.Value = user;
                            command.ExecuteNonQuery();
                            SqlParameter countParam = command.Parameters[0];
                            if (countParam != null && countParam.Value != null && countParam.Value is Int32)
                            {
                                count += (Int32)countParam.Value;
                            }
                        }
                    }

                    if (beginTranCalled)
                    {
                        (new SqlCommand("COMMIT TRANSACTION", connection)).ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                }
                catch {
                    if (beginTranCalled)
                    {
                        (new SqlCommand("ROLLBACK TRANSACTION", connection)).ExecuteNonQuery();
                        beginTranCalled = false;
                    }
                    throw;
                }
                finally {
                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }

            return(count);
        }
Esempio n. 4
0
        private int ResetUserState(ResetUserStateMode mode, DateTime userInactiveSinceDate, string[] paths, string[] usernames)
        {
            SqlConnectionHolder connectionHolder = null;
            SqlConnection       connection       = null;
            int num = 0;

            try
            {
                bool flag = false;
                try
                {
                    try
                    {
                        connectionHolder = this.GetConnectionHolder();
                        connection       = connectionHolder.Connection;
                        this.CheckSchemaVersion(connection);
                        SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_ResetUserState", connection);
                        this.SetCommandTypeAndTimeout(command);
                        SqlParameterCollection parameters = command.Parameters;
                        parameters.Add(new SqlParameter("Count", SqlDbType.Int)).Direction = ParameterDirection.Output;
                        parameters.AddWithValue("ApplicationName", this.ApplicationName);
                        string str = ((paths != null) && (paths.Length > 0)) ? paths[0] : null;
                        if (mode == ResetUserStateMode.PerInactiveDate)
                        {
                            if (userInactiveSinceDate != PersonalizationAdministration.DefaultInactiveSinceDate)
                            {
                                parameters.Add("InactiveSinceDate", SqlDbType.DateTime).Value = userInactiveSinceDate.ToUniversalTime();
                            }
                            if (str != null)
                            {
                                parameters.AddWithValue("Path", str);
                            }
                            command.ExecuteNonQuery();
                            SqlParameter parameter2 = command.Parameters[0];
                            if (((parameter2 != null) && (parameter2.Value != null)) && (parameter2.Value is int))
                            {
                                num = (int)parameter2.Value;
                            }
                        }
                        else
                        {
                            SqlParameter parameter;
                            if (mode == ResetUserStateMode.PerPaths)
                            {
                                parameter = parameters.Add("Path", SqlDbType.NVarChar);
                                foreach (string str2 in paths)
                                {
                                    if (!flag && (paths.Length > 1))
                                    {
                                        new SqlCommand("BEGIN TRANSACTION", connection).ExecuteNonQuery();
                                        flag = true;
                                    }
                                    parameter.Value = str2;
                                    command.ExecuteNonQuery();
                                    SqlParameter parameter3 = command.Parameters[0];
                                    if (((parameter3 != null) && (parameter3.Value != null)) && (parameter3.Value is int))
                                    {
                                        num += (int)parameter3.Value;
                                    }
                                }
                            }
                            else
                            {
                                if (str != null)
                                {
                                    parameters.AddWithValue("Path", str);
                                }
                                parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                                foreach (string str3 in usernames)
                                {
                                    if (!flag && (usernames.Length > 1))
                                    {
                                        new SqlCommand("BEGIN TRANSACTION", connection).ExecuteNonQuery();
                                        flag = true;
                                    }
                                    parameter.Value = str3;
                                    command.ExecuteNonQuery();
                                    SqlParameter parameter4 = command.Parameters[0];
                                    if (((parameter4 != null) && (parameter4.Value != null)) && (parameter4.Value is int))
                                    {
                                        num += (int)parameter4.Value;
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            new SqlCommand("COMMIT TRANSACTION", connection).ExecuteNonQuery();
                            flag = false;
                        }
                    }
                    catch
                    {
                        if (flag)
                        {
                            new SqlCommand("ROLLBACK TRANSACTION", connection).ExecuteNonQuery();
                            flag = false;
                        }
                        throw;
                    }
                    return(num);
                }
                finally
                {
                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch
            {
                throw;
            }
            return(num);
        }
 private int ResetUserState(ResetUserStateMode mode, DateTime userInactiveSinceDate, string[] paths,  string[] usernames)
 {
   var connection = new MySQLPersonalizationConnectionHelper(connectionString);
   connection.OpenConnection(true);
   
   try
   {
     if (ResetUserStateMode.PerInactiveDate == mode)
     {
       return PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate.ToUniversalTime(), null, null, connection);        
     }
     if (ResetUserStateMode.PerPaths == mode)
     {
       return PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate, null, paths, connection);
     }
     else
     {
       return PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate, usernames, paths, connection);        
     }
   }
   catch (Exception ex)
   {
     if (writeExceptionsToEventLog)
       WriteToEventLog(ex, "MySQLPersonalizationProvider - ResetUserState");  
     throw;
   }
   finally
   {
     connection.CloseConnection(); 
   }
 }
 private int ResetUserState(ResetUserStateMode mode, DateTime userInactiveSinceDate, string[] paths, string[] usernames)
 {
     SqlConnectionHolder connectionHolder = null;
     SqlConnection connection = null;
     int num = 0;
     try
     {
         bool flag = false;
         try
         {
             try
             {
                 connectionHolder = this.GetConnectionHolder();
                 connection = connectionHolder.Connection;
                 this.CheckSchemaVersion(connection);
                 SqlCommand command = new SqlCommand("dbo.aspnet_PersonalizationAdministration_ResetUserState", connection);
                 this.SetCommandTypeAndTimeout(command);
                 SqlParameterCollection parameters = command.Parameters;
                 parameters.Add(new SqlParameter("Count", SqlDbType.Int)).Direction = ParameterDirection.Output;
                 parameters.AddWithValue("ApplicationName", this.ApplicationName);
                 string str = ((paths != null) && (paths.Length > 0)) ? paths[0] : null;
                 if (mode == ResetUserStateMode.PerInactiveDate)
                 {
                     if (userInactiveSinceDate != PersonalizationAdministration.DefaultInactiveSinceDate)
                     {
                         parameters.Add("InactiveSinceDate", SqlDbType.DateTime).Value = userInactiveSinceDate.ToUniversalTime();
                     }
                     if (str != null)
                     {
                         parameters.AddWithValue("Path", str);
                     }
                     command.ExecuteNonQuery();
                     SqlParameter parameter2 = command.Parameters[0];
                     if (((parameter2 != null) && (parameter2.Value != null)) && (parameter2.Value is int))
                     {
                         num = (int) parameter2.Value;
                     }
                 }
                 else
                 {
                     SqlParameter parameter;
                     if (mode == ResetUserStateMode.PerPaths)
                     {
                         parameter = parameters.Add("Path", SqlDbType.NVarChar);
                         foreach (string str2 in paths)
                         {
                             if (!flag && (paths.Length > 1))
                             {
                                 new SqlCommand("BEGIN TRANSACTION", connection).ExecuteNonQuery();
                                 flag = true;
                             }
                             parameter.Value = str2;
                             command.ExecuteNonQuery();
                             SqlParameter parameter3 = command.Parameters[0];
                             if (((parameter3 != null) && (parameter3.Value != null)) && (parameter3.Value is int))
                             {
                                 num += (int) parameter3.Value;
                             }
                         }
                     }
                     else
                     {
                         if (str != null)
                         {
                             parameters.AddWithValue("Path", str);
                         }
                         parameter = parameters.Add("UserName", SqlDbType.NVarChar);
                         foreach (string str3 in usernames)
                         {
                             if (!flag && (usernames.Length > 1))
                             {
                                 new SqlCommand("BEGIN TRANSACTION", connection).ExecuteNonQuery();
                                 flag = true;
                             }
                             parameter.Value = str3;
                             command.ExecuteNonQuery();
                             SqlParameter parameter4 = command.Parameters[0];
                             if (((parameter4 != null) && (parameter4.Value != null)) && (parameter4.Value is int))
                             {
                                 num += (int) parameter4.Value;
                             }
                         }
                     }
                 }
                 if (flag)
                 {
                     new SqlCommand("COMMIT TRANSACTION", connection).ExecuteNonQuery();
                     flag = false;
                 }
             }
             catch
             {
                 if (flag)
                 {
                     new SqlCommand("ROLLBACK TRANSACTION", connection).ExecuteNonQuery();
                     flag = false;
                 }
                 throw;
             }
             return num;
         }
         finally
         {
             if (connectionHolder != null)
             {
                 connectionHolder.Close();
                 connectionHolder = null;
             }
         }
     }
     catch
     {
         throw;
     }
     return num;
 }
        private int ResetUserState(ResetUserStateMode mode,
            DateTime userInactiveSinceDate,
            string[] paths,
            string[] usernames)
        {
            SqlConnectionHolder connectionHolder = null;
            MySqlConnection connection = null;
            int count = 0;

            try {
                //bool beginTranCalled = false;
                try {
                    connectionHolder = GetConnectionHolder();
                    connection = connectionHolder.Connection;

                    CheckSchemaVersion( connection );

                    if (mode == ResetUserStateMode.PerInactiveDate)
                    {
                        count = MySqlStoredProcedures.aspnet_PersonalizationAdministration_ResetUserState(
                            ApplicationName, userInactiveSinceDate.ToUniversalTime(), null, null,
                            connectionHolder);
                    }
                    else if (mode == ResetUserStateMode.PerPaths)
                    {
                        count = MySqlStoredProcedures.aspnet_PersonalizationAdministration_ResetUserState(
                            ApplicationName, new DateTime(1754, 1, 1, 0, 0, 0), null, paths,
                            connectionHolder);
                    }
                    else
                    {
                        count = MySqlStoredProcedures.aspnet_PersonalizationAdministration_ResetUserState(
                            ApplicationName, new DateTime(1754, 1, 1, 0, 0, 0), usernames, null,
                            connectionHolder);
                    }

                    //MySqlCommand command = new MySqlCommand("dbo.aspnet_PersonalizationAdministration_ResetUserState", connection);
                    //SetCommandTypeAndTimeout(command);
                    //MySqlParameterCollection parameters = command.Parameters;

                    //MySqlParameter parameter = parameters.Add(new MySqlParameter("Count", MySqlDbType.Int32));
                    //parameter.Direction = ParameterDirection.Output;

                    //parameters.AddWithValue("ApplicationName", ApplicationName);

                    //string firstPath = (paths != null && paths.Length > 0) ? paths[0] : null;

                    //if (mode == ResetUserStateMode.PerInactiveDate) {
                    //    if (userInactiveSinceDate != DefaultInactiveSinceDate) {
                    //        // Special note: DateTime object cannot be added to collection
                    //        // via AddWithValue for some reason.
                    //        parameter = parameters.Add("InactiveSinceDate", MySqlDbType.DateTime);
                    //        parameter.Value = userInactiveSinceDate.ToUniversalTime();
                    //    }

                    //    if (firstPath != null) {
                    //        parameters.AddWithValue("Path", firstPath);
                    //    }

                    //    command.ExecuteNonQuery();
                    //    MySqlParameter countParam = command.Parameters[0];
                    //    if (countParam != null && countParam.Value != null && countParam.Value is Int32) {
                    //        count = (Int32) countParam.Value;
                    //    }
                    //}
                    //else if (mode == ResetUserStateMode.PerPaths) {
                    //    parameter = parameters.Add("Path", MySqlDbType.VarChar);
                    //    foreach (string path in paths) {
                    //        //
                    //        // Note:  ADO.NET 2.0 introduced the TransactionScope class - in your own code you should use TransactionScope
                    //        //            rather than explicitly managing transactions with the TSQL BEGIN/COMMIT/ROLLBACK statements.
                    //        //
                    //        if (!beginTranCalled && paths.Length > 1) {
                    //            (new MySqlCommand("BEGIN TRANSACTION", connection)).ExecuteNonQuery();
                    //            beginTranCalled = true;
                    //        }

                    //        parameter.Value = path;
                    //        command.ExecuteNonQuery();
                    //        MySqlParameter countParam = command.Parameters[0];
                    //        if (countParam != null && countParam.Value != null && countParam.Value is Int32) {
                    //            count += (Int32) countParam.Value;
                    //        }
                    //    }
                    //}
                    //else {
                    //    if (firstPath != null) {
                    //        parameters.AddWithValue("Path", firstPath);
                    //    }

                    //    parameter = parameters.Add("UserName", MySqlDbType.VarChar);
                    //    foreach (string user in usernames) {
                    //        //
                    //        // Note:  ADO.NET 2.0 introduced the TransactionScope class - in your own code you should use TransactionScope
                    //        //            rather than explicitly managing transactions with the TSQL BEGIN/COMMIT/ROLLBACK statements.
                    //        //
                    //        if (!beginTranCalled && usernames.Length > 1) {
                    //            (new MySqlCommand("BEGIN TRANSACTION", connection)).ExecuteNonQuery();
                    //            beginTranCalled = true;
                    //        }

                    //        parameter.Value = user;
                    //        command.ExecuteNonQuery();
                    //        MySqlParameter countParam = command.Parameters[0];
                    //        if (countParam != null && countParam.Value != null && countParam.Value is Int32) {
                    //            count += (Int32) countParam.Value;
                    //        }
                    //    }
                    //}

                    //if (beginTranCalled) {
                    //    (new MySqlCommand("COMMIT TRANSACTION", connection)).ExecuteNonQuery();
                    //    beginTranCalled = false;
                    //}
                }
                //catch {
                //    if (beginTranCalled) {
                //        (new MySqlCommand("ROLLBACK TRANSACTION", connection)).ExecuteNonQuery();
                //        beginTranCalled = false;
                //    }
                //    throw;
                //}
                finally {
                    if (connectionHolder != null) {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }

            return count;
        }
        private int ResetUserState(ResetUserStateMode mode, DateTime userInactiveSinceDate, string[] paths, string[] usernames)
        {
            int num = 0;

            using (TransactionContext context = TransactionContextFactory.EnterContext(TransactionAffinity.Required))
            {
                try
                {
                    IDataSource datasource = DataSourceFactory.GetDataSource("PersonalizationProvider");
                    IDataCommand cmd = datasource.GetCommand("aspnet_PersonalizationAdministration_ResetUserState");
                    cmd.DbCommand.CommandTimeout = this._commandTimeout;

                    cmd.Parameters["ApplicationName"].Value = this.ApplicationName;

                    string str = (paths != null && paths.Length > 0) ? paths[0] : null;

                    if (mode == ResetUserStateMode.PerInactiveDate)
                    {
                        if (userInactiveSinceDate != DateTime.MaxValue)
                            cmd.Parameters["InactiveSinceDate"].Value = userInactiveSinceDate.ToUniversalTime();

                        if (str != null)
                            cmd.Parameters["Path"].Value = str;

                        int affectedRows = cmd.ExecuteNonQuery();

                        if (((cmd.Parameters["Count"] != null) && (cmd.Parameters["Count"].Value != null)) &&
                            (cmd.Parameters["Count"].Value is int))
                            num = (int)cmd.Parameters["Count"].Value;
                    }
                    else if (mode == ResetUserStateMode.PerPaths)
                    {
                        foreach (string str2 in paths)
                        {
                            cmd.Parameters["Path"].Value = str2;

                            int affectedRows = cmd.ExecuteNonQuery();

                            if (((cmd.Parameters["Count"] != null) && (cmd.Parameters["Count"].Value != null)) &&
                                (cmd.Parameters["Count"].Value is int))
                                num += (int)cmd.Parameters["Count"].Value;
                        }
                    }
                    else
                    {
                        if (str != null)
                            cmd.Parameters["Path"].Value = str;

                        foreach (string str3 in usernames)
                        {
                            cmd.Parameters["UserName"].Value = str3;

                            int affectedRows = cmd.ExecuteNonQuery();

                            if (((cmd.Parameters["Count"] != null) && (cmd.Parameters["Count"].Value != null)) &&
                                (cmd.Parameters["Count"].Value is int))
                                num += (int)cmd.Parameters["Count"].Value;
                        }
                    }

                    context.VoteCommit();
                }
                catch
                {
                    context.VoteRollback();
                    throw;
                }
            }

            return num;
        }