Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @model List<MySolution.Data.DAL.ApplicationUser>
- @{
- ViewBag.Title = Resources.Users;
- }
- <h2>@Resources.Users</h2>
- <hr />
- <table class="table table-striped table-hover ">
- <thead>
- <tr>
- <th>@Resources.User</th>
- <th>@Resources.Roles</th>
- <th></th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- @foreach (var user in Model)
- {
- <tr>
- <td>
- @user.UserName
- </td>
- <td>
- @user.DisplayRoles()
- </td>
- <td>
- @using (Html.BeginForm("UserAssignRole", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Get, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
- @Html.HiddenFor(m => m.Where(u => u.Id.Equals(user.Id)).FirstOrDefault().UserName)
- <input type="submit" value="@Resources.AssignRole" class="btn btn-default btn-sm" />
- }
- </td>
- <td>
- @using (Html.BeginForm("UserRemoveRole", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Get, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
- @Html.HiddenFor(m => m.Where(u => u.Id.Equals(user.Id)).FirstOrDefault().UserName)
- <input type="submit" value="@Resources.RemoveRole" class="btn btn-default btn-sm" />
- }
- </td>
- </tr>
- }
- </tbody>
- </table>
- //
- // GET: /Admin/UserIndex
- [Authorize(Roles = "Admin")]
- public ActionResult UserIndex()
- {
- var users = context.Users.ToList();
- return View(users);
- }
- //
- // GET: /Admin/UserAssignRole
- [HttpGet]
- //[ValidateAntiForgeryToken]
- public ActionResult UserAssignRole(UserAssignRoleViewModel vm)
- {
- ViewBag.Username = vm.Username;
- ViewBag.Roles = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList();
- return View("UserAssignRole");
- }
- //
- // POST: /Admin/UserAssignRole
- [HttpPost]
- //[ValidateAntiForgeryToken]
- [ActionName("UserAssignRole")]
- public ActionResult UserAssignRolePost(UserAssignRoleViewModel vm)
- {
- ApplicationUser user = context.Users.Where(u => u.UserName.Equals(vm.Username, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
- this.UserManager.AddToRole(user.Id, vm.Role);
- return RedirectToAction("UserIndex");
- }
- /// <summary>
- /// ViewsAdminUserAssignRole.cshtml
- /// </summary>
- public class UserAssignRoleViewModel
- {
- [Display(Name = "Username", ResourceType = typeof(Resources))]
- public string Username { get; set; }
- [Display(Name = "Role", ResourceType = typeof(Resources))]
- public string Role { get; set; }
- }
- @model UserAssignRoleViewModel
- @{
- ViewBag.Title = Resources.AssignRole;
- }
- <h2>@Resources.AssignRole</h2>
- <hr />
- <div class="row">
- <div class="col-md-8">
- <section id="assignRoleForm">
- @using (Html.BeginForm("UserAssignRole", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(m => m.Username, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.TextBoxFor(m => m.Username, new { @class = "form-control" , @readonly = "readonly" })
- @Html.ValidationMessageFor(m => m.Username, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(m => m.Role, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.DropDownListFor(m => m.Role, (IEnumerable<SelectListItem>)ViewBag.Roles, Resources.DropdownSelect, new { @class = "form-control" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="@Resources.Assign" class="btn btn-default" />
- </div>
- </div>
- }
- </section>
- </div>
- </div>
- @model IEnumerable<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>
- @{
- ViewBag.Title = Resources.Roles;
- }
- <h2>@Resources.Roles</h2>
- <hr />
- @using (Html.BeginForm("RoleCreate", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Get, new { @class = "form-horizontal", role = "form" }))
- {
- <input type="submit" value="@Resources.CreateRole" class="btn btn-default btn-sm" />
- }
- <hr />
- <table class="table table-striped table-hover ">
- <thead>
- <tr>
- <th>@Resources.Role</th>
- <th></th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- @foreach (var role in Model)
- {
- <tr>
- <td>
- @role.Name
- </td>
- <td>
- @using (Html.BeginForm("RoleEdit", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Get, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
- @Html.HiddenFor(m => m.Where(r => r.Id.Equals(role.Id)).FirstOrDefault().Name)
- <input type="submit" value="@Resources.Edit" class="btn btn-default btn-sm" />
- }
- </td>
- <td>
- <input type="submit" value="@Resources.Delete" class="btn btn-default btn-sm" data-toggle="modal" data-target="#confirm-delete"/>
- <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- @Resources.DeleteRole
- </div>
- <div class="modal-body">
- @Resources.AreYouSureYouWantToDelete
- </div>
- <div class="modal-footer">
- @using (Html.BeginForm("RoleDelete", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
- @Html.HiddenFor(m => m.Where(r => r.Id.Equals(role.Id)).FirstOrDefault().Name)
- <button type="button" class="btn btn-default" data-dismiss="modal">@Resources.Cancel</button>
- <input type="submit" value="@Resources.Delete" class="btn btn-danger btn-ok" />
- }
- </div>
- </div>
- </div>
- </div>
- </td>
- </tr>
- }
- </tbody>
- </table>
- /// <summary>
- /// ViewsAdminRoleCreate.cshtml
- /// </summary>
- public class RoleCreateViewModel
- {
- [Required]
- [Display(Name = "Name", ResourceType = typeof(Resources))]
- public string Name { get; set; }
- }
- //
- // GET: /Admin/RoleCreate
- [HttpGet]
- [Authorize(Roles = "Admin")]
- public ActionResult RoleCreate()
- {
- return View();
- }
- //
- // POST: /Admin/RoleCreate
- [HttpPost]
- [Authorize(Roles = "Admin")]
- public ActionResult RoleCreate(RoleCreateViewModel vm)
- {
- context.Roles.Add(new IdentityRole()
- {
- Name = vm.Name
- });
- context.SaveChanges();
- ViewBag.ResultMessage = Resources.RoleCreatedSuccessfully;
- return RedirectToAction("RoleIndex");
- }
- @model RoleCreateViewModel
- @{
- ViewBag.Title = Resources.CreateRole;
- }
- <h2>@Resources.CreateRole</h2>
- <hr />
- <div class="row">
- <div class="col-md-8">
- <section id="createRoleForm">
- @using (Html.BeginForm("RoleCreate", "Admin", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
- {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary(true)
- <div class="form-group">
- @Html.LabelFor(m => m.Name, new { @class = "col-md-2 control-label" })
- <div class="col-md-10">
- @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
- @Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="@Resources.Save" class="btn btn-default" />
- </div>
- </div>
- }
- </section>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement