eCommerce Website Part 10 Gender Table
eCommerce Website Part 10 Gender Table
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 implement GenderTable form for more details click here:
watch vedio First Download Materials Download Materials.
Create BasicConfigurationController and create one by one below action's:
> Gender Table Action Code
Action Code :
public ActionResult Gender_List()
{
var list = new List<GenderMV>();
foreach (var gender in DB.GenderTables.ToList())
{
list.Add(new GenderMV()
{
GenderTitle = gender.GenderTitle,
GenderID = gender.GenderID
});
}
return View(list);
}
public ActionResult NewGender()
{
return View(new GenderMV());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult NewGender(GenderMV genderMV)
{
if (ModelState.IsValid)
{
var check_exist = DB.GenderTables.Where(a => a.GenderTitle == genderMV.GenderTitle.Trim()).FirstOrDefault();
if (check_exist == null)
{
var gender = new GenderTable();
gender.GenderTitle = genderMV.GenderTitle;
DB.GenderTables.Add(gender);
DB.SaveChanges();
return RedirectToAction("Gender_List");
}
else
{
ModelState.AddModelError("GenderTitle", "Already Registered.");
}
}
ModelState.AddModelError("GenderTitle", "Required Field");
return View(genderMV);
}
public ActionResult EditGender(int? id)
{
var gender = DB.GenderTables.Find(id);
var editgender = new GenderMV();
editgender.GenderID = gender.GenderID;
editgender.GenderTitle = gender.GenderTitle;
return View(editgender);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditGender(GenderMV genderMV)
{
if (ModelState.IsValid)
{
var check_exist = DB.GenderTables.Where(a => a.GenderTitle == genderMV.GenderTitle.Trim() && a.GenderID != genderMV.GenderID).FirstOrDefault();
if (check_exist == null)
{
var gender = DB.GenderTables.Find(genderMV.GenderID);
gender.GenderTitle = genderMV.GenderTitle;
DB.Entry(gender).State = System.Data.Entity.EntityState.Modified;
DB.SaveChanges();
return RedirectToAction("Gender_List");
}
else
{
ModelState.AddModelError("GenderTitle", "Already Registered.");
}
}
ModelState.AddModelError("GenderTitle", "Required Field");
return View(genderMV);
}
> Gender Table All Views Code
Gender List View Code:
@model IEnumerable<eCommerceUI.Models.GenderMV>
@{
ViewBag.Title = "List";
}
<div class="container">
<div class="page-width">
<h3 class="docs-title">Gender List</h3>
<p>
@Html.ActionLink("New Gender", "NewGender", null, new { @class = "btn btn--secondary" })
</p>
<div class="table-wrap">
<table class="responsive-table">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.GenderID)</th>
<th>@Html.DisplayNameFor(model => model.GenderTitle)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="responsive-table-row">
<td>#@Html.DisplayFor(modelItem => item.GenderID)</td>
<td>@Html.DisplayFor(modelItem => item.GenderTitle)</td>
<td>
@Html.ActionLink("Edit", "EditGender", new { id = item.GenderID }, new { @class = "btn" })
</td>
</tr>
}
<tbody>
</table>
</div>
</div>
</div>
New Gender View Code :
@model eCommerceUI.Models.GenderMV
@{
ViewBag.Title = "Add";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm("NewGender", "BasicConfiguration"))
{
@Html.AntiForgeryToken()
<h3 class="docs-title">New Gender</h3>
<hr />
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.GenderTitle, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.GenderTitle, new { htmlAttributes = new { @class = "form-control", placeholder = "Enter Gender Title" } })
@Html.ValidationMessageFor(model => model.GenderTitle, "", 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", "Gender_List", null, new { @class = "btn" })
</div>
</div>
</div>
}
</div>
</div>
Edit Gender View Code :
@model eCommerceUI.Models.GenderMV
@{
ViewBag.Title = "Edit";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm("EditGender", "BasicConfiguration"))
{
@Html.AntiForgeryToken()
<h3 class="docs-title">Edit Gender</h3>
<hr />
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.GenderID)
<div class="form-group">
@Html.LabelFor(model => model.GenderTitle, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.GenderTitle, new { htmlAttributes = new { @class = "form-control", placeholder = "Enter Gender Title" } })
@Html.ValidationMessageFor(model => model.GenderTitle, "", 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", "Gender_List", null, new { @class = "btn" })
</div>
</div>
</div>
}
</div>
</div>
Comments
Post a Comment