Skip to content

Instantly share code, notes, and snippets.

@BryanWilhite
Created November 12, 2014 23:09
Show Gist options
  • Save BryanWilhite/a8bef1f72041812ae16a to your computer and use it in GitHub Desktop.
Save BryanWilhite/a8bef1f72041812ae16a to your computer and use it in GitHub Desktop.
ASP.NET MVC: AccountRoleProvider
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
namespace Fox.Web.Mvc.Infrastructure
{
using Fox.Web.Mvc.Models;
/// <summary>
// Defines the contract that ASP.NET implements to
// provide role-management services using custom role providers.
/// </summary>
/// <remarks>
/// For more, see “ASP.Net MVC 3 Custom Membership Provider with Repository Injection”
/// by Dan Harman [http://www.danharman.net/2011/06/23/asp-net-mvc-3-custom-membership-provider-with-repository-injection/]
/// </remarks>
public class AccountRoleProvider : RoleProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="AccountRoleProvider"/> class.
/// </summary>
public AccountRoleProvider()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AccountRoleProvider"/> class.
/// </summary>
/// <param name="applicationName">Name of the application.</param>
/// <param name="repository">The repository.</param>
public AccountRoleProvider(string applicationName, IAccountRepository repository)
{
this.ApplicationName = applicationName;
this._repository = repository;
}
/// <summary>
/// Gets or sets the name of the application to store and retrieve role information for.
/// </summary>
/// <returns>The name of the application to store and retrieve role information for.</returns>
public override string ApplicationName { get; set; }
/// <summary>
/// Gets a list of the roles that a specified user is in for the configured applicationName.
/// </summary>
/// <param name="username">The user to return a list of roles for.</param>
/// <returns>
/// A string array containing the names of all the roles that the specified user is in for the configured applicationName.
/// </returns>
public override string[] GetRolesForUser(string username)
{
throw new NotImplementedException();
}
/// <summary>
/// Gets a value indicating whether the specified role name already exists in the role data source for the configured applicationName.
/// </summary>
/// <param name="roleName">The name of the role to search for in the data source.</param>
/// <returns>
/// true if the role name already exists in the data source for the configured applicationName; otherwise, false.
/// </returns>
public override bool RoleExists(string roleName)
{
throw new NotImplementedException();
}
IAccountRepository _repository;
#region not implemented:
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
public override void CreateRole(string roleName)
{
throw new NotImplementedException();
}
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
{
throw new NotImplementedException();
}
public override string[] FindUsersInRole(string roleName, string usernameToMatch)
{
throw new NotImplementedException();
}
public override string[] GetAllRoles()
{
throw new NotImplementedException();
}
public override string[] GetUsersInRole(string roleName)
{
throw new NotImplementedException();
}
public override bool IsUserInRole(string username, string roleName)
{
throw new NotImplementedException();
}
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
{
throw new NotImplementedException();
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment