Online Restaurant Website Part 39 Place Order
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 Payment tab for more details click here: watch vedio
First we are going to open project , then go to order controller:
Create Cart method to use in both ViewCart and View Cart post action or method, add ViewCart Action code to "Cart" method, how? show in code below. then call "Cart" method in ViewCart get method.
> Cart Method:
public ShoppingCartMV Cart(int 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"
});
}
return shoppingcart;
}
> ViewCart get method : (Updated 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 shoppingcart = Cart(userid); // here call cart method to get shopping cart details...
ViewBag.UserAddressID = new SelectList(Db.UserAddressTables.Where(ua => ua.UserID == userid).ToList(), "UserAddressID", "FullAddress", "0");
ViewBag.OrderTypeID = new SelectList(Db.OrderTypeTables.ToList(), "OrderTypeID", "OrderType", "0");
return View(shoppingcart);
}
Next go to module folder and open ShoppingCartMV model and add some field to optimise ShoppingCartMV model code.
this field is actually use getting order receiver details.
> ShoppingCartMV Model :
// step 1 : add empty constructor
public ShoppingCartMV()
{
Cart_Items = new List<CartMV>();
}
// step 2 : add some field to store order receiver details
public string FirstName { get; set; }
public string LastName { get; set; }
public string ContactNo { get; set; }
//step 3 : remove User_ProfileMV property or field
public User_ProfileMV User_info { get; set; }
// step 4 : update existing constructor code
public ShoppingCartMV(int userid)
{
Cart_Items = new List<CartMV>();
var user = Db.UserTables.Find(userid);
FirstName = user.FirstName;
LastName = user.LastName;
ContactNo = user.ContactNo;
}
Comments
Post a Comment