using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace PizzaRestaurantDrink.Models
{
public class Reg_UserMV
{
public int UserID { get; set; }
[Required(ErrorMessage="Required*")]
public int UserTypeID { get; set; }
[Required(ErrorMessage = "Required*")]
[DataType(DataType.Text)]
[Display(Name ="User Name")]
public string UserName { get; set; }
[Required(ErrorMessage = "Required*")]
[DataType(DataType.Password)]
public string Password { get; set; }
[Required(ErrorMessage = "Required*")]
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "Not Match!")]
public string ConfirmPassword { get; set; }
[Required(ErrorMessage = "Required*")]
[DataType(DataType.Text)]
[Display(Name = "First Name")]
public string FirstName { get; set; }
public string LastName { get; set; }
[Required(ErrorMessage = "Required*")]
[DataType(DataType.PhoneNumber)]
[Display(Name = "Contact No")]
public string ContactNo { get; set; }
[Required(ErrorMessage = "Required*")]
[Display(Name = "Select Gender")]
public int GenderID { get; set; }
[Required(ErrorMessage = "Required*")]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email Address")]
public string EmailAddress { get; set; }
public System.DateTime RegisterationDate { get; set; }
public int UserStatusID { get; set; }
public Nullable<System.DateTime> UserStatusChangeDate { get; set; }
}
}
public ActionResult Register()
{
var user = new Reg_UserMV();
ViewBag.GenderID = new SelectList(Db.GenderTables.ToList(), "GenderID", "GenderTitle", "0");
return View(user);
}
[HttpPost]
public ActionResult Register(Reg_UserMV reg_UserMV)
{
reg_UserMV.UserTypeID = 4; // Customer User_Type_ID
reg_UserMV.RegisterationDate = DateTime.Now;
reg_UserMV.UserStatusID = 1;
if (ModelState.IsValid)
{
bool isexist = false;
var checkexist = Db.UserTables.Where(u => u.UserName.ToUpper().Trim() == reg_UserMV.UserName.ToUpper().Trim()).FirstOrDefault();
if (checkexist != null)
{
isexist = true;
ModelState.AddModelError("UserName", "Already Exist!");
}
checkexist = Db.UserTables.Where(u => u.EmailAddress.ToUpper().Trim() == reg_UserMV.EmailAddress.ToUpper().Trim()).FirstOrDefault();
if (checkexist != null)
{
isexist = true;
ModelState.AddModelError("EmailAddress", "Already Exist!");
}
if (isexist == false)
{
var user = new UserTable();
user.UserTypeID = reg_UserMV.UserTypeID;
user.UserName = reg_UserMV.UserName;
user.Password = reg_UserMV.Password;
user.FirstName = reg_UserMV.FirstName;
user.LastName = reg_UserMV.LastName;
user.ContactNo = reg_UserMV.ContactNo;
user.GenderID = reg_UserMV.GenderID;
user.EmailAddress = reg_UserMV.EmailAddress;
user.RegisterationDate = reg_UserMV.RegisterationDate;
user.UserStatusID = reg_UserMV.UserStatusID;
Db.UserTables.Add(user);
Db.SaveChanges();
return RedirectToAction("Login","User");
}
}
ViewBag.GenderID = new SelectList(Db.GenderTables.ToList(), "GenderID", "GenderTitle", reg_UserMV.GenderID);
return View(reg_UserMV);
}
@model PizzaRestaurantDrink.Models.Reg_UserMV
@{
ViewBag.Title = "Register";
}
<!-- Breadcrumb Start -->
<div class="bread-crumb">
<div class="container">
<div class="matter">
<h2>Register</h2>
<ul class="list-inline">
<li class="list-inline-item"><a href="@Url.Content("~/Home/Index")">HOME</a></li>
<li class="list-inline-item"><a href="@Url.Content("~/User/Register")">Register</a></li>
</ul>
</div>
</div>
</div>
<!-- Breadcrumb End -->
<!-- User Register Start -->
<div class="login">
<div class="container">
<div class="row justify-content-center">
<div class="col-sm-12 commontop text-center">
<h4>Create an Account</h4>
<div class="divider style-1 center">
<span class="hr-simple left"></span>
<i class="icofont icofont-ui-press hr-icon"></i>
<span class="hr-simple right"></span>
</div>
</div>
<div class="col-lg-10 col-md-12">
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="loginnow" style="height: 920px;">
<h5>Register</h5>
<p>Do You have an account? So <a href="@Url.Content("~/User/Login")">login</a> And starts less than a minute</p>
@using (Html.BeginForm("Register", "User", FormMethod.Post, new { @enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<i class="icofont icofont-ui-user"></i>
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter First Name" } })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-ui-user"></i>
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Last Name" } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-ui-user"></i>
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter User Name" } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-ui-message"></i>
@Html.EditorFor(model => model.EmailAddress, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Email Address" } })
@Html.ValidationMessageFor(model => model.EmailAddress, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-lock"></i>
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Password" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-lock"></i>
@Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control", @placeholder = "Confirm Password" } })
@Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-phone"></i>
@Html.EditorFor(model => model.ContactNo, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Contact No" } })
@Html.ValidationMessageFor(model => model.ContactNo, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-people"></i>
@Html.DropDownList("GenderID", null, "--Choose Gender--", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.GenderID, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<div class="links">
<label><input type="checkbox" class="checkbox-inline" /> By signing up I agree with <a href="#">terms & conditions.</a> </label>
</div>
</div>
<div class="form-group">
<input type="submit" value="SIGN UP" class="btn btn-theme btn-md btn-wide" />
</div>
}
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="loginto loginnow">
<h5>Login via social accounts</h5>
<ul class="list-unstyled text-center">
<li><a href="#" target="_blank"><i class="icofont icofont-social-facebook"></i> Login with Facebook</a></li>
<li><a href="#" target="_blank"><i class="icofont icofont-social-google-plus"></i> Login with Google+</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- User Register End -->
Comments
Post a Comment