public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
{
if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0)
{
throw new ProviderException("Cannot delete a populated role.");
}
_documentStore.DatabaseCommands.UpdateByIndex("Users/ByApplicationNameAndRoleName",
new IndexQuery{ Query = string.Format("ApplicationName:{0} AND RoleName:{1} ", ApplicationName, roleName) },
new[]
{
new PatchRequest()
{
Type = PatchCommandType.Remove,
Name = "Roles",
Value = roleName
}
});
using (var session = _documentStore.OpenSession())
{
var app = session.Query<Application>().SingleOrDefault(x => x.Name == ApplicationName);
if (app == null)
{
return false;
}
app.Roles.Remove(roleName);
session.SaveChanges();
}
return true;
}