Mineplex2018-withcommit/Website/LOC.Website.Web/Views/Account/ManageRoles.cshtml

112 lines
3.2 KiB
Plaintext
Raw Normal View History

2013-08-27 17:14:08 +02:00
@{
var roleName = "";
string[] userNames = new string[1];
string[] roleNames = new string[1];
if(IsPost){
// Create new role
if(!Request["buttonCreateRole"].IsEmpty()){
roleName=Request["textRoleName"];
if(!Roles.RoleExists(roleName) && !roleName.IsEmpty()){
Roles.CreateRole(roleName);
}
} // if(buttonCreateRole)
// Delete role
if(!Request["buttonDeleteRole"].IsEmpty()){
roleName=Request["textRoleName"];
if(Roles.GetUsersInRole(roleName).Length == 0 && !roleName.IsEmpty())
{
Roles.DeleteRole(roleName, true); // true means throw if any users are in this role
}
} // if(buttonDeleteRole)
// Add user to role
if(!Request["buttonAddUserToRole"].IsEmpty()){
userNames[0] = Request["selectUserName"];
roleNames[0] = Request["selectRoleName"];
if(!Roles.IsUserInRole(userNames[0], roleNames[0])){
Roles.AddUsersToRoles(userNames, roleNames);
}
} // if(buttonAddUserToRole)
// Delete user from role
if(!Request["buttonDeleteUserFromRole"].IsEmpty()){
userNames[0] = Request["selectUserName"];
roleNames[0] = Request["selectRoleName"];
if(Roles.IsUserInRole(userNames[0], roleNames[0])){
Roles.RemoveUsersFromRoles(userNames, roleNames);
}
} // if(buttonDeleteUseFromRole)
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="@Href("~/")TestMembership.css" type="text/css" />
<meta charset="utf-8" />
<title>Manage Roles</title>
<style type="text/css">
fieldset{width:92%;}
</style>
</head>
<body>
<h1>Manage Roles</h1>
<form method="post">
<fieldset>
<label for="textRoleName">Role name:</label><br/>
<input type="text" value="" name="textRoleName" /> &nbsp;
<input type="submit" value="Create Role" name="buttonCreateRole" />
<input type="submit" value="Delete Role" name="buttonDeleteRole" />
</fieldset>
<p></p>
<fieldset>
<label for="selectUserName">Users:</label>
<select name="selectUserName">
@foreach (MembershipUser row in Membership.GetAllUsers())
{
<option>@row.UserName</option>
}
</select>
&nbsp;
<label for="selectRoleName">Roles:</label>
<select name="selectRoleName">
@foreach(string r in Roles.GetAllRoles())
{
<option>@r</option>
}
</select>
&nbsp;
<input type="submit" value="Add User to Role" name="buttonAddUserToRole" />
<input type="submit" value="Delete User from Role" name="buttonDeleteUserFromRole" />
</fieldset>
<h2>Roles</h2>
<ul>
@foreach(var r in Roles.GetAllRoles())
{
<li>@r</li>
<ul>
@foreach(var u in Roles.GetUsersInRole(r))
{
<li>@u</li>
}
</ul>
}
</ul>
<p><a href="@Href("~/Home")">Return to home page</a></p>
</form>
</body>
</html>