Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. public class userInfo
  2. {
  3. [Key]
  4. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  5. public int userID { get; set; }
  6.  
  7. [Required(ErrorMessage = "First name is required")]
  8. public string firstName { get; set; }
  9.  
  10. [Required(ErrorMessage = "Last name is required")]
  11. public string lastName { get; set; }
  12.  
  13. [Required(ErrorMessage = "Email is required")]
  14. [EmailAddress]
  15. public string email { get; set; }
  16.  
  17. [Required(ErrorMessage = "Username is required")]
  18. public string userName { get; set; }
  19.  
  20. [Required(ErrorMessage = "Password is required")]
  21. [DataType(DataType.Password)]
  22. public string password { get; set; }
  23.  
  24. /*[NotMapped]
  25. [Compare("Password", ErrorMessage = "Please confirm your password")]
  26. [DataType(DataType.Password)]
  27. public string confirmPassword { get; set; }*/
  28. }
  29.  
  30. public DbSet<userInfo> Users { get; set; }
  31.  
  32. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  33. {
  34. base.OnModelCreating(modelBuilder);
  35. modelBuilder.Entity<userInfo>().ToTable("tblusers");
  36. }
  37.  
  38. public ActionResult Register()
  39. {
  40. return View();
  41. }
  42.  
  43. [HttpPost]
  44. public ActionResult Register(FormCollection userBuild)
  45. {
  46. userInfoViewModel vm = new userInfoViewModel();
  47.  
  48. userInfo user = new userInfo();
  49. user.firstName = Request.Form["firstName"];
  50. user.lastName = Request.Form["lastName"];
  51. user.email = Request.Form["email"];
  52. user.userName = Request.Form["userName"];
  53. user.password = Request.Form["password"];
  54.  
  55. if (ModelState.IsValid)
  56. {
  57. try
  58. {
  59. userInfoDal Dal = new userInfoDal();
  60. Dal.Users.Add(user);
  61. Dal.SaveChanges();
  62. vm.newUser = new userInfo();
  63. }
  64. catch
  65. {
  66. return View("Register");
  67. }
  68. }
  69. else
  70. {
  71. vm.newUser = user;
  72. }
  73. userInfoDal dal = new userInfoDal();
  74. return View("Register");
  75. }
  76.  
  77. <h2>Registration</h2>
  78.  
  79. @using (Html.BeginForm("Register", "Account", FormMethod.Post))
  80. {
  81. @Html.AntiForgeryToken()
  82.  
  83. <div class="form-horizontal">
  84. <h4>New User Registration</h4>
  85. <hr />
  86. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  87. <div class="form-group">
  88. @Html.LabelFor(model => model.userName, htmlAttributes: new { @class = "control-label col-md-2" })
  89. <div class="col-md-10">
  90. @Html.EditorFor(model => model.userName, new { htmlAttributes = new { @class = "form-control" } })
  91. @Html.ValidationMessageFor(model => model.userName, "", new { @class = "text-danger" })
  92. </div>
  93. </div>
  94.  
  95. <div class="form-group">
  96. @Html.LabelFor(model => model.firstName, htmlAttributes: new { @class = "control-label col-md-2" })
  97. <div class="col-md-10">
  98. @Html.EditorFor(model => model.firstName, new { htmlAttributes = new { @class = "form-control" } })
  99. @Html.ValidationMessageFor(model => model.firstName, "", new { @class = "text-danger" })
  100. </div>
  101. </div>
  102.  
  103. <div class="form-group">
  104. @Html.LabelFor(model => model.lastName, htmlAttributes: new { @class = "control-label col-md-2" })
  105. <div class="col-md-10">
  106. @Html.EditorFor(model => model.lastName, new { htmlAttributes = new { @class = "form-control" } })
  107. @Html.ValidationMessageFor(model => model.lastName, "", new { @class = "text-danger" })
  108. </div>
  109. </div>
  110.  
  111. <div class="form-group">
  112. @Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
  113. <div class="col-md-10">
  114. @Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
  115. @Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
  116. </div>
  117. </div>
  118.  
  119. <div class="form-group">
  120. @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
  121. <div class="col-md-10">
  122. @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } })
  123. @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
  124. </div>
  125. </div>
  126.  
  127. @*<div class="form-group">
  128. @Html.LabelFor(model => model.confirmPassword, htmlAttributes: new { @class = "control-label col-md-2" })
  129. <div class="col-md-10">
  130. @Html.EditorFor(model => model.confirmPassword, new { htmlAttributes = new { @class = "form-control" } })
  131. @Html.ValidationMessageFor(model => model.confirmPassword, "", new { @class = "text-danger" })
  132. </div>
  133. </div>-->*@
  134.  
  135. <div class="form-group">
  136. <div class="col-md-offset-2 col-md-10">
  137. <input id="Submit1" type="submit" value="Register" class="btn btn-default" />
  138. </div>
  139. </div>
  140. </div>
  141. }
  142.  
  143. <div>
  144. @Html.ActionLink("Back to List", "Index")
  145. </div>
  146.  
  147. public userInfo newUser { get; set; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement