本文整理汇总了C#中RoleManager.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# RoleManager.Delete方法的具体用法?C# RoleManager.Delete怎么用?C# RoleManager.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RoleManager
的用法示例。
在下文中一共展示了RoleManager.Delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: deleteRole
public ActionResult deleteRole(string roleID)
{
ajaxReturnData data = new ajaxReturnData();
try
{
using (ApplicationDbContext DB = new ApplicationDbContext())
{
ApplicationUser user = new ApplicationUser();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(DB));
IdentityRole role = roleManager.FindById(roleID);
string name = role.Name;
roleManager.Delete(role);
data.statusCode = (int)statusCodes.successRun;
data.message = "Role '" + name + "' removed";
}
}
catch (Exception ex)
{
data.statusCode = (int)statusCodes.fail;
data.message = "Failed to remove role; Error is: " + ex.Message;
}
return Json(data);
}
示例2: DeleteRole
public ActionResult DeleteRole(string roleName)
{
//ApplicationDbContext is the a classe is used by the ASP.NET Identity to manage user records
var context = new ApplicationDbContext();
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
var deletedRole = roleManager.FindByName(roleName);
roleManager.Delete(deletedRole);
return RedirectToAction("RolesIndex", "Account");
}
示例3: DeleteRoledb
private string DeleteRoledb(string RoleName)
{
var result = "";
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
if (RoleManager.RoleExists(RoleName))
{
var roleresult = RoleManager.Delete(new IdentityRole(RoleName));
result = "Successful";
}
else { result= "It doesn't exist"; }
return result;
}
示例4: DeleteRole_Click
protected void DeleteRole_Click(object sender, EventArgs e)
{
var manager = new RoleManager<CustomRole,int>(new CustomRoleStore(new ApplicationDbContext()));
manager.Create(new CustomRole() { Name = Rolename.Text });
var result = manager.Delete(manager.FindByName(Rolename.Text));
if (!result.Succeeded)
{
throw new Exception("role not deleted");
}
}
示例5: RoleDelete
public ActionResult RoleDelete(string roleName)
{
using (var context = new ApplicationDbContext())
{
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
var role = roleManager.FindByName(roleName);
roleManager.Delete(role);
context.SaveChanges();
}
ViewBag.ResultMessage = "Role deleted succesfully !";
return RedirectToAction("RoleIndex", "Account");
}
示例6: Delete
public JsonData Delete(string id, string userId)
{
try
{
using (var db = new DataContext())
{
if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException("The record was" + " no passed");
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(db));
//Update Role Roles if they do not exist
var role = db.Roles.FirstOrDefault(x => x.Id == id);
roleManager.Delete(role);
db.SaveChanges();
return DataHelpers.ReturnJsonData(id, true, "Deleted successfully", 1);
}
}
catch (Exception e)
{
return DataHelpers.ExceptionProcessor(e);
}
}