Online Restaurant Website Part 33 Shopping Cart View
Hi, Dear's here we learn how to implement "Pizza Restaurant Drink" Website in Visual S
tudio 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 Shopping Cart View for more details click here:
watch vedioFirst we are going to open project and create CartMV model, CartMV model is the format of data in view. model code below:
> CartMV :
namespace PizzaRestaurantDrink.Models
{
public class CartMV
{
public int CartID { get; set; }
public int CartItemID { get; set; }
public int StockItemID { get; set; }
public string StockItemTitle { get; set; }
public string ItemPhotoPath { get; set; }
public string ItemSize { get; set; }
public double UnitPrice { get; set; }
public int Qty { get; set; }
public double ItemCost { get; set; } // = Qty * Unit Price
public string ItemType { get; set; } // it's deal or item
}
}
Once CartMV is created successfully then to Order Controller.
in order controller we create ViewCart Action so in ViewCart Action first we create list of CartMV to store cart deal and items to pass in return view as a model. code below
public ActionResult ViewCart()
{
if (string.IsNullOrEmpty(Convert.ToString(Session["UserTypeID"])))
{
return RedirectToAction("Login", "User");
}
int userid = 0;
int.TryParse(Convert.ToString(Session["UserID"]), out userid);
var cart = Db.CartTables.Where(u => u.UserID == userid).FirstOrDefault();
var cartdetails = new List<CartMV>();
foreach (var cart_item in Db.CartItemDetailTables.Where(i => i.CartID == cart.CartID).ToList())
{
var stockitem = Db.StockItemTables.Find(cart_item.StockItemID);
cartdetails.Add(new CartMV()
{
CartID = cart.CartID,
CartItemID = cart_item.CartItemID,
StockItemID = cart_item.StockItemID,
StockItemTitle = stockitem.StockItemTitle,
ItemPhotoPath = stockitem.ItemPhotoPath,
ItemSize = stockitem.ItemSize,
UnitPrice = stockitem.UnitPrice,
Qty = cart_item.Qty,
ItemCost = stockitem.UnitPrice * cart_item.Qty,
ItemType = "item"
});
}
foreach (var cart_deal in Db.CartDealTables.Where(d => d.CartID == cart.CartID).ToList())
{
var stockdeal = Db.StockDealTables.Find(cart_deal.StockDealID);
cartdetails.Add(new CartMV()
{
CartID = cart.CartID,
CartItemID = cart_deal.CartDealID,
StockItemID = cart_deal.StockDealID,
StockItemTitle = stockdeal.StockDealTitle,
ItemPhotoPath = stockdeal.DealPhoto,
ItemSize = "Normal",
UnitPrice = stockdeal.DealPrice,
Qty = cart_deal.Qty,
ItemCost = stockdeal.DealPrice * cart_deal.Qty,
ItemType = "Deal"
});
}
return View(cartdetails);
}
once all the above steps is complete then right click in ViewCart Action and create view. in ViewCart view we are going to show cart design and also items. code is below.
ViewCart Designing Code :
@model IEnumerable<PizzaRestaurantDrink.Models.CartMV>
@{
ViewBag.Title = "Shopping Cart";
double totalamount = 0;
}
<!-- Breadcrumb Start -->
<div class="bread-crumb">
<div class="container">
<div class="matter">
<h2>Shopping Cart</h2>
<ul class="list-inline">
<li class="list-inline-item"><a href="@Url.Content("~/Home/Index")">HOME</a></li>
<li class="list-inline-item"><a href="@Url.Content("~/Order/ViewCart")">Shopping Cart</a></li>
</ul>
</div>
</div>
</div>
<!-- Breadcrumb End -->
<!-- Cart Start -->
<div class="mycart">
<div class="container">
<div class="row">
<div class="col-sm-12">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" href="#tab-cart" data-toggle="tab"><span>1</span>shopping cart</a></li>
</ul>
<div class="bor"></div>
<div class="tab-content">
<div class="tab-pane active" id="tab-cart">
<form method="post" enctype="multipart/form-data">
<h2>You have <span>@(Model != null ? Model.Count() : 0) items</span> in your order.</h2>
<div class="table-responsive-md">
<table class="table table-bordered">
<thead>
<tr>
<td class="text-center">Name</td>
<td class="text-center">Price</td>
<td class="text-center">Qty.</td>
<td class="text-center">Total</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
totalamount = totalamount + item.ItemCost;
<tr>
<td>
<a href="#">
<img width="100" height="100" src="@Url.Content(item.ItemPhotoPath)" class="img-fluid" alt="thumb" title="thumb" />
</a>
<div class="name">
<h4>@item.StockItemTitle</h4>
<p>Curses / Dictum / Risus</p>
<div class="rating">
<i class="icofont icofont-star"></i>
<i class="icofont icofont-star"></i>
<i class="icofont icofont-star"></i>
<i class="icofont icofont-star"></i>
<i class="icofont icofont-star"></i>
</div>
</div>
</td>
<td class="text-center">PKR @item.UnitPrice</td>
<td class="text-center">
<p class="qtypara">
<span id="minus1" class="minus"><i class="icofont icofont-minus"></i></span>
<input type="text" name="quantity" value="@item.Qty" size="2" id="input-quantity1" class="form-control qty" />
<span id="add1" class="add"><i class="icofont icofont-plus"></i></span>
<input type="hidden" name="product_id" value="1" />
</p>
</td>
<td class="text-center">PKR @item.ItemCost</td>
<td class="text-center">
<button type="button" onclick="deleteitem(@item.CartItemID,'@item.ItemType')"><i class="icofont icofont-close-line"></i></button>
</td>
</tr>
}
<tr>
<td colspan="5">
<h3 class="text-right">SUBTOTAL - PKR @totalamount</h3>
<div class="buttons float-left">
<a href="@Url.Content("~/Home/AllItems")" class="btn btn-theme btn-md btn-wide">Continue Shopping</a>
</div>
<div class="buttons float-right">
<a href="#tab-info" data-toggle="tab" class="btn btn-theme btn-md btn-wide">Checkout</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Cart End -->
so once all above steps is done then run the application...
Comments
Post a Comment