Esempio n. 1
0
        public static bool IncrementVotes(
            Guid pollGuid,
            Guid optionGuid,
            Guid userGuid)
        {
            if (DBPoll.UserHasVoted(pollGuid, userGuid))
            {
                return(false);
            }

            StringBuilder sqlCommand = new StringBuilder();

            if (userGuid != Guid.Empty)
            {
                sqlCommand.Append("INSERT INTO mp_PollUsers (");
                sqlCommand.Append("PollGuid, ");
                sqlCommand.Append("OptionGuid, ");
                sqlCommand.Append("UserGuid )");

                sqlCommand.Append(" VALUES (");
                sqlCommand.Append("?PollGuid, ");
                sqlCommand.Append("?OptionGuid, ");
                sqlCommand.Append("?UserGuid )");
                sqlCommand.Append(";");
            }


            sqlCommand.Append("UPDATE mp_PollOptions ");
            sqlCommand.Append("SET  ");

            sqlCommand.Append("Votes = Votes + 1 ");

            sqlCommand.Append("WHERE  ");
            sqlCommand.Append("OptionGuid = ?OptionGuid ");
            sqlCommand.Append(";");

            MySqlParameter[] arParams = new MySqlParameter[3];

            arParams[0]           = new MySqlParameter("?OptionGuid", MySqlDbType.VarChar, 36);
            arParams[0].Direction = ParameterDirection.Input;
            arParams[0].Value     = optionGuid.ToString();

            arParams[1]           = new MySqlParameter("?PollGuid", MySqlDbType.VarChar, 36);
            arParams[1].Direction = ParameterDirection.Input;
            arParams[1].Value     = pollGuid.ToString();

            arParams[2]           = new MySqlParameter("?UserGuid", MySqlDbType.VarChar, 36);
            arParams[2].Direction = ParameterDirection.Input;
            arParams[2].Value     = userGuid.ToString();

            int rowsAffected = MySqlHelper.ExecuteNonQuery(
                ConnectionString.GetWriteConnectionString(),
                sqlCommand.ToString(),
                arParams);

            return(rowsAffected > 0);
        }
Esempio n. 2
0
        public static bool IncrementVotes(
            Guid pollGuid,
            Guid optionGuid,
            Guid userGuid)
        {
            if (DBPoll.UserHasVoted(pollGuid, userGuid))
            {
                return(false);
            }

            StringBuilder sqlCommand = new StringBuilder();

            if (userGuid != Guid.Empty)
            {
                sqlCommand.Append("INSERT INTO mp_pollusers (");
                sqlCommand.Append("pollguid, ");
                sqlCommand.Append("optionguid, ");
                sqlCommand.Append("userguid )");

                sqlCommand.Append(" VALUES (");
                sqlCommand.Append(":pollguid, ");
                sqlCommand.Append(":optionguid, ");
                sqlCommand.Append(":userguid )");
                sqlCommand.Append(";");
            }

            sqlCommand.Append("UPDATE mp_polloptions ");
            sqlCommand.Append("SET  ");
            sqlCommand.Append("votes = votes + 1 ");
            sqlCommand.Append("WHERE  ");
            sqlCommand.Append("optionguid = :optionguid ");
            sqlCommand.Append(";");

            NpgsqlParameter[] arParams = new NpgsqlParameter[3];

            arParams[0]           = new NpgsqlParameter("pollguid", NpgsqlTypes.NpgsqlDbType.Char, 36);
            arParams[0].Direction = ParameterDirection.Input;
            arParams[0].Value     = pollGuid.ToString();

            arParams[1]           = new NpgsqlParameter("optionguid", NpgsqlTypes.NpgsqlDbType.Char, 36);
            arParams[1].Direction = ParameterDirection.Input;
            arParams[1].Value     = optionGuid.ToString();

            arParams[2]           = new NpgsqlParameter("userguid", NpgsqlTypes.NpgsqlDbType.Char, 36);
            arParams[2].Direction = ParameterDirection.Input;
            arParams[2].Value     = userGuid.ToString();

            int rowsAffected = NpgsqlHelper.ExecuteNonQuery(
                ConnectionString.GetWriteConnectionString(),
                CommandType.Text,
                sqlCommand.ToString(),
                arParams);

            return(rowsAffected > 0);
        }
Esempio n. 3
0
        public static bool IncrementVotes(
            Guid pollGuid,
            Guid optionGuid,
            Guid userGuid)
        {
            if (DBPoll.UserHasVoted(pollGuid, userGuid))
            {
                return(false);
            }

            SqlCeParameter[] arParams = new SqlCeParameter[3];

            arParams[0]           = new SqlCeParameter("@PollGuid", SqlDbType.UniqueIdentifier);
            arParams[0].Direction = ParameterDirection.Input;
            arParams[0].Value     = pollGuid;

            arParams[1]           = new SqlCeParameter("@OptionGuid", SqlDbType.UniqueIdentifier);
            arParams[1].Direction = ParameterDirection.Input;
            arParams[1].Value     = optionGuid;

            arParams[2]           = new SqlCeParameter("@UserGuid", SqlDbType.UniqueIdentifier);
            arParams[2].Direction = ParameterDirection.Input;
            arParams[2].Value     = userGuid;

            int rowsAffected;

            StringBuilder sqlCommand = new StringBuilder();

            if (userGuid != Guid.Empty)
            {
                sqlCommand.Append("INSERT INTO mp_PollUsers (");
                sqlCommand.Append("PollGuid, ");
                sqlCommand.Append("OptionGuid, ");
                sqlCommand.Append("UserGuid )");

                sqlCommand.Append(" VALUES (");
                sqlCommand.Append("@PollGuid, ");
                sqlCommand.Append("@OptionGuid, ");
                sqlCommand.Append("@UserGuid )");
                sqlCommand.Append(";");

                rowsAffected = SqlHelper.ExecuteNonQuery(
                    GetConnectionString(),
                    CommandType.Text,
                    sqlCommand.ToString(),
                    arParams);
            }

            sqlCommand = new StringBuilder();
            sqlCommand.Append("UPDATE mp_PollOptions ");
            sqlCommand.Append("SET  ");

            sqlCommand.Append("Votes = Votes + 1 ");

            sqlCommand.Append("WHERE  ");
            sqlCommand.Append("OptionGuid = @OptionGuid ");
            sqlCommand.Append(";");

            arParams = new SqlCeParameter[3];

            arParams[0]           = new SqlCeParameter("@PollGuid", SqlDbType.UniqueIdentifier);
            arParams[0].Direction = ParameterDirection.Input;
            arParams[0].Value     = pollGuid;

            arParams[1]           = new SqlCeParameter("@OptionGuid", SqlDbType.UniqueIdentifier);
            arParams[1].Direction = ParameterDirection.Input;
            arParams[1].Value     = optionGuid;

            arParams[2]           = new SqlCeParameter("@UserGuid", SqlDbType.UniqueIdentifier);
            arParams[2].Direction = ParameterDirection.Input;
            arParams[2].Value     = userGuid;

            rowsAffected = SqlHelper.ExecuteNonQuery(
                GetConnectionString(),
                CommandType.Text,
                sqlCommand.ToString(),
                arParams);

            return(rowsAffected > -1);
        }