eCommerce Website Part 6 User Types Complete
eCommerce Website Part 6 User Types Complete
Hi, Dear's here we learn how to implement eCommerce Website in Visual Studio using C# ASP.NET MVC. Ilyasoft software company provide full project step by step training on our YouTube Channel ilyasoft software company so now subscribe, share and like for more project base tutorials
In this video we are going to design user types views form for more details click here: > View User Type List:
Code :
@model IEnumerable<eCommerceUI.Models.UserTypeMV>
@{
ViewBag.Title = "UserTypes_List";
}
<div class="container">
<div class="page-width">
<h3 class="docs-title">User Type List</h3>
<p>
@Html.ActionLink("New User Type", "NewUserType", null, new { @class = "btn btn--secondary" })
</p>
<div class="table-wrap">
<table class="responsive-table">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.UserTypeID)</th>
<th>@Html.DisplayNameFor(model => model.UserType)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="responsive-table-row">
<td>#@Html.DisplayFor(modelItem => item.UserTypeID)</td>
<td>@Html.DisplayFor(modelItem => item.UserType)</td>
<td>
@Html.ActionLink("Edit", "EditUserType", new { id = item.UserTypeID }, new { @class="btn"})
</td>
</tr>
}
<tbody>
</table>
</div>
</div>
</div>
> New User Type :
Action Code :
public ActionResult NewUserType()
{
return View(new UserTypeMV());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult NewUserType(UserTypeMV userTypeMV)
{
if (ModelState.IsValid)
{
var usertype = new UserTypeTable();
usertype.UserType = userTypeMV.UserType;
DB.UserTypeTables.Add(usertype);
DB.SaveChanges();
return RedirectToAction("UserTypes_List");
}
ModelState.AddModelError("UserType", "User Type is Required");
return View(userTypeMV);
}
> View New User Type:
Code :
@model eCommerceUI.Models.UserTypeMV
@{
ViewBag.Title = "New User Type";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm("NewUserType", "BasicConfiguration"))
{
@Html.AntiForgeryToken()
<h3 class="docs-title">New User Type</h3>
<hr />
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.UserType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserType, new { htmlAttributes = new { @class = "form-control", placeholder = "Enter User Type" } })
@Html.ValidationMessageFor(model => model.UserType, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn--secondary" />
@Html.ActionLink("Back to List", "UserTypes_List", null, new { @class = "btn" })
</div>
</div>
</div>
}
</div>
</div>
> Edit User Type:
Action Code :
public ActionResult EditUserType(int? id)
{
var usertype = DB.UserTypeTables.Find(id);
return View(usertype);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditUserType(UserTypeMV userTypeMV)
{
if (ModelState.IsValid)
{
var usertype = DB.UserTypeTables.Find(userTypeMV.UserTypeID);
usertype.UserType = userTypeMV.UserType;
DB.UserTypeTables.Add(usertype);
DB.SaveChanges();
return RedirectToAction("UserTypes_List");
}
ModelState.AddModelError("UserType", "User Type is Required");
return View(userTypeMV);
}
> View Edit User Type:
@model DatabaseLayer.UserTypeTable
@{
ViewBag.Title = "Edit";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm("NewUserType", "BasicConfiguration"))
{
@Html.AntiForgeryToken()
<h3 class="docs-title">Edit User Type</h3>
<hr />
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.UserTypeID)
<div class="form-group">
@Html.LabelFor(model => model.UserType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserType, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserType, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn--secondary" />
@Html.ActionLink("Back to List", "UserTypes_List", null, new { @class = "btn" })
</div>
</div>
</div>
}
</div>
</div>
Comments
Post a Comment