Guest User

Untitled

a guest
Jan 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. public class UserViewModel
  2. {
  3. [Display(Name = "User Name")]
  4. public string UserName { get; set; }
  5. public string Email { get; set; }
  6. [StringLength(int.MaxValue, MinimumLength = 6, ErrorMessage = "Password is at least 6 characters.")]
  7. public string Password { get; set; }
  8. [Display(Name = "Confirm Password")]
  9. [CompareAttribute("Password", ErrorMessage = "Password doesn't match.")]
  10. public string ConfirmPassword { get; set; }
  11. public string Role { get; set; }
  12. }
  13.  
  14. public class AdminController : Controller
  15. {
  16. private ApplicationDbContext _context;
  17.  
  18. public AdminController()
  19. {
  20. _context = new ApplicationDbContext();
  21. }
  22. // GET: Admin
  23. public ActionResult Index()
  24. {
  25. return View();
  26. }
  27. public ActionResult Create()
  28. {
  29. var viewModel = new UserViewModel();
  30. return View(viewModel);
  31. }
  32. public ActionResult CreateUser(UserViewModel viewModel)
  33. {
  34. var user = new ApplicationUser
  35. {
  36. Email = viewModel.Email,
  37. UserName = viewModel.UserName
  38. };
  39. return View("Index");
  40. }
  41. }
  42.  
  43. @model HMSMVC.ViewModel.UserViewModel
  44. @{
  45. ViewBag.Title = "Create";
  46. }
  47.  
  48. <h2>Create</h2>
  49.  
  50. @using (Html.BeginForm())
  51. {
  52. @Html.AntiForgeryToken()
  53.  
  54. <div class="form-horizontal">
  55. <h4>ApplicationUser</h4>
  56. <hr />
  57. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  58.  
  59. <div class="form-group">
  60. @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
  61. <div class="col-md-10">
  62. @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
  63. @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
  64. </div>
  65. </div>
  66. <div class="form-group">
  67. @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
  68. <div class="col-md-10">
  69. @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
  70. @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
  71. </div>
  72. </div>
  73. <div class="form-group">
  74. @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
  75. <div class="col-md-10">
  76. @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", type = "password" } })
  77. @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
  78. </div>
  79. </div>
  80. <div class="form-group">
  81. @Html.LabelFor(model => model.ConfirmPassword, htmlAttributes: new { @class = "control-label col-md-2" })
  82. <div class="col-md-10">
  83. @Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control", type = "password" } })
  84. @Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
  85. </div>
  86. </div>
  87. <div class="form-group">
  88. @Html.LabelFor(model => model.Role, htmlAttributes: new { @class = "control-label col-md-2" })
  89. <div class="col-md-10">
  90. @Html.DropDownListFor(model=>model.Role,new SelectList( new List<Object>
  91. {
  92. new{value = "Doctor", text = "Doctor"},
  93. new{value = "Receptionist", text = "Receptionist"}
  94. }, "value", "text"), "Select a Role",new{@class="form-control"})
  95. @Html.ValidationMessageFor(model => model.Role, "", new { @class = "text-danger" })
  96. </div>
  97. </div>
  98. <div class="form-group">
  99. <div class="col-md-offset-2 col-md-10">
  100. <input type="submit" value="Create" class="btn btn-default" />
  101. </div>
  102. </div>
  103. </div>
  104. }
  105.  
  106. <div>
  107. @Html.ActionLink("Back to List", "Index")
  108. </div>
  109. @section scripts {
  110. @Scripts.Render("~/bundles/jqueryval")
  111. }
Add Comment
Please, Sign In to add comment