AspnetRolesCommands Partial Class

This command factory creates static partial classes that generate parameterized database commands to the ASP.NET database, in this case the “Roles” table. This partial class could be extended to include your own queries if you desired.

[csharp]

 //*****************************************************************************
// This file is part of the data access layer example to the ASP.NET 2.0 provider database
// This file was written by Adam Buenz [WSS MVP] of ARB Security Solutions, LLC
// http://www.sharepointsecurity.com
//
// This file and its parts is free for re-distribution, for use in both free
// and commercial applications, however this header must remain intact for legal
// use. The data access layer example is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//*****************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Aspnet.Provider.Datalayer.Commands
{
///

/// A command factory class for AspnetRoles objects.
///

internal static partial class AspnetRolesCommands
{
///

/// Finds all AspnetRoles objects with a certain Applicationid value.
///

/// The Applicationid value. /// An IDbCommand that finds all AspnetRoles objects with a certain Applicationid value.
public static IDbCommand FindByApplicationid(Guid applicationid)
{
SqlCommand cmd;
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [ApplicationId] = @applicationid”);
cmd.Parameters.AddWithValue(“@applicationid”, applicationid);
return cmd;
}

///

/// Finds all AspnetRoles objects with a certain Rolename value.
///

/// The Rolename value (‘*’ can be used as a wildcard). /// An IDbCommand that finds all AspnetRoles objects with a certain Rolename value.
public static IDbCommand FindByRolename(string rolename)
{
SqlCommand cmd;
if (rolename == null)
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [RoleName] is null”);
else
{
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [RoleName] like @rolename”);
cmd.Parameters.AddWithValue(“@rolename”, rolename.Replace(“*”, “%”));
}
return cmd;
}

///

/// Finds all AspnetRoles objects with a certain Loweredrolename value.
///

/// The Loweredrolename value (‘*’ can be used as a wildcard). /// An IDbCommand that finds all AspnetRoles objects with a certain Loweredrolename value.
public static IDbCommand FindByLoweredrolename(string loweredrolename)
{
SqlCommand cmd;
if (loweredrolename == null)
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [LoweredRoleName] is null”);
else
{
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [LoweredRoleName] like @loweredrolename”);
cmd.Parameters.AddWithValue(“@loweredrolename”, loweredrolename.Replace(“*”, “%”));
}
return cmd;
}

///

/// Finds all AspnetRoles objects with a certain Description value.
///

/// The Description value (‘*’ can be used as a wildcard). /// An IDbCommand that finds all AspnetRoles objects with a certain Description value.
public static IDbCommand FindByDescription(string description)
{
SqlCommand cmd;
if (description == null)
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [Description] is null”);
else
{
cmd = new SqlCommand(“select * from [dbo].[aspnet_Roles] where [Description] like @description”);
cmd.Parameters.AddWithValue(“@description”, description.Replace(“*”, “%”));
}
return cmd;
}

}
}

 

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *