Online Restaurant Website Part 37 Shopping Cart Info

  Online Restaurant Website Part 37 Shopping Cart Info

Hi, Dear's here we learn how to implement "Pizza Restaurant Drink" 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 Shopping Cart info tab for more details click here: watch vedio

First we are going to open project , add StockItemCategory property in CartMV and create ShoppingCartMV model code below:

> ShoppingCartMV Action Code: 

 public class ShoppingCartMV
 {
     PizzaRestaurentandDrinksDbEntities Db = new PizzaRestaurentandDrinksDbEntities();
     public ShoppingCartMV(int userid)
     {
         Cart_Items = new List<CartMV>();
         var user = Db.UserTables.Find(userid);
         User_info = new User_ProfileMV();
         User_info.FirstName = user.FirstName;
         User_info.LastName = user.LastName;
         User_info.ContactNo = user.ContactNo;
         User_info.EmailAddress = user.EmailAddress;
     }
     public List<CartMV> Cart_Items { get; set; }
     public User_ProfileMV User_info { get; set; }
     public int UserAddressID { get; set; }
     public int OrderTypeID { get; set; }

 }

> ViewCart Action Update Code: 

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 shoppingcart = new ShoppingCartMV(userid);
    var user = Db.UserTables.Find(userid);
    
    int cartid = (cart != null ? cart.CartID : 0);
    foreach (var cart_item in Db.CartItemDetailTables.Where(i => i.CartID == cartid).ToList())
    {
        var stockitem = Db.StockItemTables.Find(cart_item.StockItemID);
        shoppingcart.Cart_Items.Add(new CartMV()
        {
            CartID = cart.CartID,
            CartItemID = cart_item.CartItemID,
            StockItemID = cart_item.StockItemID,
            StockItemTitle = stockitem.StockItemTitle,
            StockItemCategory = stockitem.StockItemCategoryTable.StockItemCategory,
            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 == cartid).ToList())
    {
        var stockdeal = Db.StockDealTables.Find(cart_deal.StockDealID);
        shoppingcart.Cart_Items.Add(new CartMV()
        {
            CartID = cart.CartID,
            CartItemID = cart_deal.CartDealID,
            StockItemID = cart_deal.StockDealID,
            StockItemTitle = stockdeal.StockDealTitle,
            StockItemCategory = "Deal",
            ItemPhotoPath = stockdeal.DealPhoto,
            ItemSize = "Normal",
            UnitPrice = stockdeal.DealPrice,
            Qty = cart_deal.Qty,
            ItemCost = stockdeal.DealPrice * cart_deal.Qty,
            ItemType = "Deal"
        });
    }

    ViewBag.UserAddressID = new SelectList(Db.UserAddressTables.Where(ua=>ua.UserID == userid).ToList(), "UserAddressID", "FullAddress", "0");
    ViewBag.OrderTypeID = new SelectList(Db.OrderTypeTables.ToList(), "OrderTypeID", "OrderType", "1");

    return View(shoppingcart);
}


 Add Update Code for Shopping Info in ViewCart View 

<ul class="nav nav-tabs">
    ...........
    <li class="nav-item"><a class="nav-link" href="#tab-info" data-toggle="tab"><span>2</span>shopping info</a></li>
</ul>

<div class="tab-pane col-md-12 col-12" id="tab-info">
    <div class="row">
        <div class="col-lg-5 col-md-6 col-12">
            <h6>Shopping Address & Order Type</h6>
            <form method="post" enctype="multipart/form-data">
                <fieldset>
                    <div class="form-group">
                        @Html.DropDownList("OrderTypeID", null, "--Order Type--", htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.OrderTypeID, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group">
                        @Html.DropDownList("UserAddressID", null, "--Choose Address--", htmlAttributes: new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.UserAddressID, "", new { @class = "text-danger" })
                    </div>
                </fieldset>
            </form>
        </div>

        <div class="col-lg-2 d-none d-lg-block"></div>
        <div class="col-lg-5 col-md-6 col-12">
            <h6>Contact information</h6>
            <form method="post" enctype="multipart/form-data">
                <fieldset>
                    <div class="form-group">
                        <input name="firstname" value="@Model.User_info.FirstName" placeholder="First Name" id="input-firstname" class="form-control" type="text">
                    </div>
                    <div class="form-group">
                        <input name="lastname" value="@Model.User_info.LastName" placeholder="Last Name" id="input-lastname" class="form-control" type="text">
                    </div>
                    <div class="form-group">
                        <input name="email" value="@Model.User_info.EmailAddress" placeholder="Email" id="input-email" class="form-control" type="text">
                    </div>
                    <div class="form-group">
                        <input name="phone" value="@Model.User_info.ContactNo" placeholder="Phone Number" id="input-phone" class="form-control" type="text">
                    </div>
                </fieldset>
            </form>
        </div>
        <div class="col-md-12 col-12">
            <div class="buttons float-left">
                <a href="#tab-cart" data-toggle="tab" class="btn btn-theme btn-md btn-wide">Shopping Cart</a>
            </div>
            <div class="buttons float-right">
                <a href="#tab-payment" data-toggle="tab" class="btn btn-theme btn-md btn-wide">Continue</a>
            </div>
        </div>
    </div>
</div>

so once all above steps is done then run the application... 

Comments