@model IEnumerable<eCommerceUI.Models.AddressTypeMV>
@{
ViewBag.Title = "Address Types";
}
<div class="container">
<div class="page-width">
<h3 class="docs-title">Address Types List</h3>
<p>
@Html.ActionLink("New Address Type", "NewAddressType", null, new { @class = "btn btn--secondary" })
</p>
<div class="table-wrap">
<table class="responsive-table">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.AddressTypeID)</th>
<th>@Html.DisplayNameFor(model => model.AddressType)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="responsive-table-row">
<td>#@Html.DisplayFor(modelItem => item.AddressTypeID)</td>
<td>@Html.DisplayFor(modelItem => item.AddressType)</td>
<td>
@Html.ActionLink("Edit", "EditAddressType", new { id = item.AddressTypeID }, new { @class = "btn" })
</td>
</tr>
}
<tbody>
</table>
</div>
</div>
</div>
@model eCommerceUI.Models.AddressTypeMV
@{
ViewBag.Title = "New Address Type";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm("NewAddressType", "BasicConfiguration"))
{
@Html.AntiForgeryToken()
<h3 class="docs-title">New Address Type</h3>
<hr />
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.AddressType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.AddressType, new { htmlAttributes = new { @class = "form-control", placeholder = "Enter Address Type" } })
@Html.ValidationMessageFor(model => model.AddressType, "", 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", "AddressTypes_List", null, new { @class = "btn" })
</div>
</div>
</div>
}
</div>
</div>
> Edit Address Type:
Action Code :
public ActionResult EditAddressType(int? id)
{
var addresstype = DB.AddressTypeTables.Find(id);
var editaddresstype = new AddressTypeMV();
editaddresstype.AddressTypeID = addresstype.AddressTypeID;
editaddresstype.AddressType = addresstype.AddressType;
return View(editaddresstype);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditAddressType(AddressTypeMV addressTypeMV)
{
if (ModelState.IsValid)
{
var check_exist = DB.AddressTypeTables.Where(a => a.AddressType == addressTypeMV.AddressType.Trim() && a.AddressTypeID != addressTypeMV.AddressTypeID).FirstOrDefault();
if (check_exist == null)
{
var addresstype = DB.AddressTypeTables.Find(addressTypeMV.AddressTypeID);
addresstype.AddressType = addressTypeMV.AddressType;
DB.Entry(addresstype).State = System.Data.Entity.EntityState.Modified;
DB.SaveChanges();
return RedirectToAction("AddressTypes_List");
}
else
{
ModelState.AddModelError("AddressType", "Address Type Already Registered.");
}
}
ModelState.AddModelError("AddressType", "Address Type is Required");
return View(addressTypeMV);
}
View Code :
@model eCommerceUI.Models.AddressTypeMV
@{
ViewBag.Title = "Edit";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm("EditAddressType", "BasicConfiguration"))
{
@Html.AntiForgeryToken()
<h3 class="docs-title">Edit Address Type</h3>
<hr />
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.AddressTypeID)
<div class="form-group">
@Html.LabelFor(model => model.AddressType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.AddressType, new { htmlAttributes = new { @class = "form-control", placeholder="Enter Address Type" } })
@Html.ValidationMessageFor(model => model.AddressType, "", 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", "AddressTypes_List", null, new { @class = "btn" })
</div>
</div>
</div>
}
</div>
</div>
Comments
Post a Comment