Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class userInfo
- {
- [Key]
- [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- public int userID { get; set; }
- [Required(ErrorMessage = "First name is required")]
- public string firstName { get; set; }
- [Required(ErrorMessage = "Last name is required")]
- public string lastName { get; set; }
- [Required(ErrorMessage = "Email is required")]
- [EmailAddress]
- public string email { get; set; }
- [Required(ErrorMessage = "Username is required")]
- public string userName { get; set; }
- [Required(ErrorMessage = "Password is required")]
- [DataType(DataType.Password)]
- public string password { get; set; }
- /*[NotMapped]
- [Compare("Password", ErrorMessage = "Please confirm your password")]
- [DataType(DataType.Password)]
- public string confirmPassword { get; set; }*/
- }
- public DbSet<userInfo> Users { get; set; }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- base.OnModelCreating(modelBuilder);
- modelBuilder.Entity<userInfo>().ToTable("tblusers");
- }
- public ActionResult Register()
- {
- return View();
- }
- [HttpPost]
- public ActionResult Register(FormCollection userBuild)
- {
- userInfoViewModel vm = new userInfoViewModel();
- userInfo user = new userInfo();
- user.firstName = Request.Form["firstName"];
- user.lastName = Request.Form["lastName"];
- user.email = Request.Form["email"];
- user.userName = Request.Form["userName"];
- user.password = Request.Form["password"];
- if (ModelState.IsValid)
- {
- try
- {
- userInfoDal Dal = new userInfoDal();
- Dal.Users.Add(user);
- Dal.SaveChanges();
- vm.newUser = new userInfo();
- }
- catch
- {
- return View("Register");
- }
- }
- else
- {
- vm.newUser = user;
- }
- userInfoDal dal = new userInfoDal();
- return View("Register");
- }
- <h2>Registration</h2>
- @using (Html.BeginForm("Register", "Account", FormMethod.Post))
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>New User Registration</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(model => model.userName, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.userName, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.userName, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.firstName, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.firstName, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.firstName, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.lastName, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.lastName, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.lastName, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
- </div>
- </div>
- @*<div class="form-group">
- @Html.LabelFor(model => model.confirmPassword, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.confirmPassword, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.confirmPassword, "", new { @class = "text-danger" })
- </div>
- </div>-->*@
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input id="Submit1" type="submit" value="Register" class="btn btn-default" />
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- public userInfo newUser { get; set; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement