Guest User

Untitled

a guest
Nov 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. @using (Html.BeginForm())
  2. {
  3. @Html.AntiForgeryToken()
  4.  
  5. <div class="form-horizontal" style="padding:20px 10px;">
  6. <h2>Edit User Details</h2>
  7. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  8. <div class="form-group">
  9. @Html.LabelFor(model => model.Username, htmlAttributes: new { @class = "control-label col-md-2" })
  10. <div class="col-md-10">
  11. @Html.EditorFor(model => model.Username, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
  12. </div>
  13. </div>
  14.  
  15. <div class="form-group">
  16. @Html.LabelFor(model => model.CreatedOn, htmlAttributes: new { @class = "control-label col-md-2" })
  17. <div class="col-md-10">
  18. @Html.EditorFor(model => model.CreatedOn, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
  19. </div>
  20. </div>
  21.  
  22. <div class="form-group">
  23. @Html.LabelFor(model => model.Role, htmlAttributes: new { @class = "control-label col-md-2" })
  24. <div class="col-md-10">
  25. @Html.DropDownListFor(model => model.SelectedRole, new SelectList(Model._RolesList, "Value", "Text", Model.RoleId))
  26. @Html.ValidationMessageFor(model => model.SelectedRole, "", new { @class = "text-danger" })
  27. </div>
  28. </div>
  29. @Html.HiddenFor(model => model.RoleId)
  30. @Html.HiddenFor(model => model.UserId)
  31.  
  32. <div class="form-group">
  33. <div class="col-md-offset-2 col-md-10">
  34. <input type="submit" value="Save" class="btn btn-default" />
  35. </div>
  36. </div>
  37. </div>
  38. }
  39.  
  40. <div>
  41. @Html.ActionLink("Back to List", "Index")
  42. </div>
  43.  
  44. <script src="~/Scripts/jquery-1.10.2.min.js"></script>
  45. <script src="~/Scripts/jquery.validate.min.js"></script>
  46. <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
  47.  
  48. public ActionResult Edit(int userid)
  49. {
  50. UserModel result = this._webClient.DownloadData<UserModel>("getregistereduser",new { Userid = userid }, false);
  51. EditUserModel _edituser = new EditUserModel();
  52. _edituser.UserId = result.UserId;
  53. _edituser.Username = result.Username;
  54. _edituser.CreatedOn = result.CreatedOn;
  55. _edituser.Role = result.Role;
  56. _edituser.RoleId = result.RoleId;
  57. RolesList _rolelist = this._webClient.DownloadData<RolesList>("getuserroles", null, false);
  58. foreach (var item in _rolelist._UserRoles)
  59. {
  60. _edituser._RolesList.Add(new SelectListItem()
  61. {
  62. Text = item.Role,
  63. Value = item.Id.ToString(),
  64. Selected = (item.Id == result.RoleId ? true:false),
  65.  
  66. });
  67. }
  68. return View(_edituser);
  69. }
  70.  
  71. [HttpPost]
  72. public ActionResult Edit(EditUserModel user)
  73. {
  74. if(ModelState.IsValid)
  75. {
  76. if(user.SelectedRole != user.RoleId)
  77. {
  78. API_Status result = this._webClient.UploadData<API_Status>("Admin/edituser", new { Userid = user.UserId, Roleid = user.SelectedRole }, false);
  79. if (result == API_Status.Sucess)
  80. TempData["Success"] = "Updated Successfully!";
  81. else if (result == API_Status.UserAlreadyExist)
  82. TempData["Success"] = "Updation cannot be completed";
  83. else
  84. TempData["Success"] = "Some Error Occured";
  85. }
  86. return RedirectToAction("List");
  87. }
  88. else
  89. {
  90. return View(user);
  91. }
  92. }
Add Comment
Please, Sign In to add comment