Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Authorize(Roles = "Admin")]
- [HttpPost]
- [ChildActionOnly]
- public ActionResult _GetUserRoles(string UserName)
- {
- SqlParameter param1 = new SqlParameter("@UserName", UserName);
- try
- {
- IList<GetUserRolesViewModel> roles = Identitydb.Database.SqlQuery<GetUserRolesViewModel>("admin.sp_GetUserRoles @UserName",
- ((ICloneable)param1).Clone()).ToArray().ToList();
- return View(roles);
- }
- catch (Exception ex)
- {
- ViewBag.Error = ex.ToString();
- return RedirectToAction("ErrorSaveData");
- }
- }
- @model IEnumerable<AMSIdentity.Controllers.GetUserRolesViewModel>
- @if (Model == null)
- {
- <table></table>
- }
- else
- {
- <table class="table table-responsive table-striped table-hover table-bordered table-condensed container" style="margin-top: 5%;">
- <thead>
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.Name)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Id)
- </th>
- </tr>
- </thead>
- <tbody>
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.Name)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.Id)
- </td>
- </tr>
- }
- </tbody>
- </table>
- <br />
- @Html.ActionLink("Return Back", "RemoveRoleFromUser", "Manage")
- }
- ViewBag.Title = "RemoveRoleFromUser";
- var error = ViewBag.Error as IEnumerable<String>;
- }
- <h2> Remove role from user </h2>
- <ul></ul>
- <div class="row container">
- <div class="col-md-6">
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.Label("Username", htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.Editor("UserName", new { htmlAttributes = new { @class = "form-control" } })
- </div>
- <hr />
- @Html.Label("Role Id", htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.Editor("RoleId", new { htmlAttributes = new { @class = "form-control" } })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Remove" class="btn btn-default btn-danger" />
- </div>
- </div>
- </div>
- }
- </div>
- <div class="col-md-6">
- <div class="row container">
- <div class="col-md-12">
- <h3> Get user roles </h3>
- @using (Html.BeginForm("_GetUserRoles", "Manage", FormMethod.Post))
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.Label("Username", htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.Editor("UserName", new { htmlAttributes = new { @class = "form-control" } })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Get rules" class="btn btn-default btn-success" id="btnRules"/>
- </div>
- </div>
- </div>
- }
- </div>
- </div>
- <div class="row container">
- <div class="col-md-12">
- @Html.Partial("_GetUserRoles")
- </div>
- </div>
- </div><!--Second Column-->
- </div> <!--End of row-->
- @section Scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
- public class GetUserRolesViewModel
- {
- [DisplayName("Username")]
- public string Name { get; set; }
- [Key]
- [DisplayName("Role Id")]
- public string Id { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement