Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. [Authorize(Roles = "Admin")]
  2. [HttpPost]
  3. [ChildActionOnly]
  4. public ActionResult _GetUserRoles(string UserName)
  5. {
  6. SqlParameter param1 = new SqlParameter("@UserName", UserName);
  7. try
  8. {
  9. IList<GetUserRolesViewModel> roles = Identitydb.Database.SqlQuery<GetUserRolesViewModel>("admin.sp_GetUserRoles @UserName",
  10. ((ICloneable)param1).Clone()).ToArray().ToList();
  11. return View(roles);
  12. }
  13. catch (Exception ex)
  14. {
  15. ViewBag.Error = ex.ToString();
  16. return RedirectToAction("ErrorSaveData");
  17. }
  18. }
  19.  
  20. @model IEnumerable<AMSIdentity.Controllers.GetUserRolesViewModel>
  21.  
  22.  
  23. @if (Model == null)
  24. {
  25. <table></table>
  26. }
  27. else
  28. {
  29. <table class="table table-responsive table-striped table-hover table-bordered table-condensed container" style="margin-top: 5%;">
  30. <thead>
  31. <tr>
  32. <th>
  33. @Html.DisplayNameFor(model => model.Name)
  34. </th>
  35. <th>
  36. @Html.DisplayNameFor(model => model.Id)
  37. </th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. @foreach (var item in Model)
  42. {
  43. <tr>
  44. <td>
  45. @Html.DisplayFor(modelItem => item.Name)
  46. </td>
  47. <td>
  48. @Html.DisplayFor(modelItem => item.Id)
  49. </td>
  50. </tr>
  51. }
  52. </tbody>
  53. </table>
  54.  
  55. <br />
  56.  
  57. @Html.ActionLink("Return Back", "RemoveRoleFromUser", "Manage")
  58. }
  59.  
  60. ViewBag.Title = "RemoveRoleFromUser";
  61. var error = ViewBag.Error as IEnumerable<String>;
  62. }
  63.  
  64. <h2> Remove role from user </h2>
  65. <ul></ul>
  66. <div class="row container">
  67. <div class="col-md-6">
  68.  
  69. @using (Html.BeginForm())
  70. {
  71. @Html.AntiForgeryToken()
  72.  
  73. <div class="form-horizontal">
  74. <hr />
  75. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  76.  
  77. <div class="form-group">
  78. @Html.Label("Username", htmlAttributes: new { @class = "control-label col-md-2" })
  79. <div class="col-md-10">
  80. @Html.Editor("UserName", new { htmlAttributes = new { @class = "form-control" } })
  81. </div>
  82. <hr />
  83. @Html.Label("Role Id", htmlAttributes: new { @class = "control-label col-md-2" })
  84. <div class="col-md-10">
  85. @Html.Editor("RoleId", new { htmlAttributes = new { @class = "form-control" } })
  86. </div>
  87.  
  88. </div>
  89.  
  90. <div class="form-group">
  91. <div class="col-md-offset-2 col-md-10">
  92. <input type="submit" value="Remove" class="btn btn-default btn-danger" />
  93. </div>
  94. </div>
  95. </div>
  96. }
  97.  
  98. </div>
  99.  
  100. <div class="col-md-6">
  101.  
  102. <div class="row container">
  103. <div class="col-md-12">
  104. <h3> Get user roles </h3>
  105. @using (Html.BeginForm("_GetUserRoles", "Manage", FormMethod.Post))
  106. {
  107. @Html.AntiForgeryToken()
  108. <div class="form-horizontal">
  109. <hr />
  110. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  111.  
  112. <div class="form-group">
  113. @Html.Label("Username", htmlAttributes: new { @class = "control-label col-md-2" })
  114. <div class="col-md-10">
  115. @Html.Editor("UserName", new { htmlAttributes = new { @class = "form-control" } })
  116. </div>
  117.  
  118. </div>
  119.  
  120. <div class="form-group">
  121. <div class="col-md-offset-2 col-md-10">
  122. <input type="submit" value="Get rules" class="btn btn-default btn-success" id="btnRules"/>
  123. </div>
  124. </div>
  125. </div>
  126. }
  127. </div>
  128. </div>
  129.  
  130. <div class="row container">
  131. <div class="col-md-12">
  132. @Html.Partial("_GetUserRoles")
  133. </div>
  134. </div>
  135.  
  136.  
  137. </div><!--Second Column-->
  138.  
  139. </div> <!--End of row-->
  140.  
  141.  
  142. @section Scripts {
  143. @Scripts.Render("~/bundles/jqueryval")
  144. }
  145.  
  146. public class GetUserRolesViewModel
  147. {
  148. [DisplayName("Username")]
  149. public string Name { get; set; }
  150. [Key]
  151. [DisplayName("Role Id")]
  152. public string Id { get; set; }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement