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