eCommerce Website Part 21 Brands
eCommerce Website Part 21 Brands
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 Sub Categories for more details click here:
watch vedio > BrandMV Code :
public class BrandMV
{
public int BrandID { get; set; }
public string BrandTitle { get; set; }
public string StatusTitle { get; set; }
}
> Reg_RegBrandMV Code :
public class Reg_BrandMV
{
public Reg_BrandMV()
{
List_Status = new List<StatusMV>();
foreach (var status in new DatabaseLayer.Pro_EcommerceDbEntities().StatusTables.ToList())
{
List_Status.Add(new StatusMV()
{
StatusID = status.StatusID,
StatusTitle = status.StatusTitle
});
}
List_Brands = new List<BrandMV>();
foreach (var brand in new DatabaseLayer.Pro_EcommerceDbEntities().BrandTables.ToList())
{
var status = new DatabaseLayer.Pro_EcommerceDbEntities().StatusTables.Find(brand.StatusID);
List_Brands.Add(new BrandMV()
{
BrandID = brand.BrandID,
BrandTitle = brand.BrandTitle,
StatusTitle = status.StatusTitle
});;
}
}
public Reg_BrandMV(int? id)
{
List_Status = new List<StatusMV>();
foreach (var status in new DatabaseLayer.Pro_EcommerceDbEntities().StatusTables.ToList())
{
List_Status.Add(new StatusMV()
{
StatusID = status.StatusID,
StatusTitle = status.StatusTitle
});
}
List_Brands = new List<BrandMV>();
foreach (var brand in new DatabaseLayer.Pro_EcommerceDbEntities().BrandTables.ToList())
{
var status = new DatabaseLayer.Pro_EcommerceDbEntities().StatusTables.Find(brand.StatusID);
List_Brands.Add(new BrandMV()
{
BrandID = brand.BrandID,
BrandTitle = brand.BrandTitle,
StatusTitle = status.StatusTitle
}); ;
}
var editbrand = new DatabaseLayer.Pro_EcommerceDbEntities().BrandTables.Find(id);
if (editbrand != null)
{
BrandID = editbrand.BrandID;
BrandTitle = editbrand.BrandTitle;
StatusID = editbrand.StatusID;
}
else
{
BrandID = 0;
BrandTitle = string.Empty;
StatusID = 0;
}
}
[Display(Name = "S No")]
public int BrandID { get; set; }
[Required(ErrorMessage = "Required*")]
[Display(Name = "Brand Title")]
public string BrandTitle { get; set; }
[Required(ErrorMessage = "Required*")]
[Display(Name = "Status")]
public int StatusID { get; set; }
public List<StatusMV> List_Status { get; set; }
public virtual List<BrandMV> List_Brands { get; set; }
}
> Brand Action Code :
add below code.
public ActionResult Brand(int? id)
{
if (string.IsNullOrEmpty(Convert.ToString(Session["UserID"])))
{
return RedirectToAction("Login", "User");
}
int userid = 0;
int.TryParse(Convert.ToString(Session["UserID"]), out userid);
var brand = new Reg_BrandMV(id);
return View(brand);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Brand(Reg_BrandMV reg_BrandMV)
{
if (string.IsNullOrEmpty(Convert.ToString(Session["UserID"])))
{
return RedirectToAction("Login", "User");
}
int userid = 0;
int.TryParse(Convert.ToString(Session["UserID"]), out userid);
if (ModelState.IsValid)
{
if (reg_BrandMV.BrandID == 0)
{
var checkexist = DB.BrandTables.Where(b => b.BrandTitle == reg_BrandMV.BrandTitle).FirstOrDefault();
if (checkexist == null)
{
var createbrand = new BrandTable();
createbrand.BrandTitle = reg_BrandMV.BrandTitle;
createbrand.StatusID = reg_BrandMV.StatusID;
DB.BrandTables.Add(createbrand);
DB.SaveChanges();
return RedirectToAction("Brand", new { id = 0 });
}
else
{
ModelState.AddModelError("BrandTitle", "Already Added!");
}
}
else
{
var checkexist = DB.BrandTables.Where(b => b.BrandTitle == reg_BrandMV.BrandTitle && b.BrandID != reg_BrandMV.BrandID).FirstOrDefault();
if (checkexist == null)
{
var editBrand = DB.BrandTables.Find(reg_BrandMV.BrandID);
editBrand.BrandTitle = reg_BrandMV.BrandTitle;
editBrand.StatusID = reg_BrandMV.StatusID;
DB.Entry(editBrand).State = System.Data.Entity.EntityState.Modified;
DB.SaveChanges();
return RedirectToAction("Brand", new { id = 0 });
}
else
{
ModelState.AddModelError("BrandTitle", "Already Added!");
}
}
}
return View(reg_BrandMV);
}
> Brand View Code :
@model eCommerceUI.Models.Reg_BrandMV
@{
ViewBag.Title = "Brands";
}
<div class="container">
<div class="page-width">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<hr />
<h3 class="docs-title text-center">Brands</h3>
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.BrandID)
<div class="row" style="margin-left:1px;">
<div class="form-group col-md-3">
@Html.LabelFor(model => model.BrandTitle, "Enter Brand Title", htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.BrandTitle, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BrandTitle, "", new { @class = "text-danger" })
</div>
<div class="form-group col-md-3">
@Html.LabelFor(model => model.StatusID, "Select Status", htmlAttributes: new { @class = "control-label" })
@Html.DropDownList("StatusID", new SelectList(Model.List_Status, "StatusID", "StatusTitle", Model.StatusID), "--Choose--", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.StatusID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
@if (Model.BrandID == 0)
{
<input type="submit" value="Create" class="btn btn--secondary" />
}
else
{
<input type="submit" value="Update" class="btn btn--secondary" />
}
</div>
</div>
</div>
}
<hr />
<h3 class="docs-title">Brands List</h3>
<form autocomplete="off">
<p>
<div style="float:right;">
<input type="text"
style="background-image: url('@Url.Content("~/Content/Template/images/searchicon.png")');
background-position: 10px 5px;
background-repeat: no-repeat;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px; "
class="search form-control"
id="myInput"
placeholder="What you looking for?">
</div>
</p>
</form>
<div class="table">
<table class="responsive-table">
<thead>
<tr>
<td>#Unique No</td>
<td>Brand Title</td>
<td>Status</td>
<th>Action</th>
</tr>
</thead>
<tbody id="myTable">
@foreach (var item in Model.List_Brands)
{
<tr class="responsive-table-row">
<td>#@Html.DisplayFor(modelItem => item.BrandID)</td>
<td>@Html.DisplayFor(modelItem => item.BrandTitle)</td>
<td>
@if (item.StatusTitle == "Visible")
{
<span class="label label--new mb-3 mr-3 text-nowrap">
@Html.DisplayFor(modelItem => item.StatusTitle)
</span>
}
else
{
<span class="label label--sale mb-3 mr-3 text-nowrap">
@Html.DisplayFor(modelItem => item.StatusTitle)
</span>
}
</td>
<td>
@Html.ActionLink("Edit", "Brand", new { id = item.BrandID }, new { @class = "btn" })
</td>
</tr>
}
<tbody>
</table>
</div>
</div>
</div>
Comments
Post a Comment