public ActionResult OrderAdd(int id, int Ord) { id = int.Parse(Session["idProduct"].ToString()); Ord = int.Parse(Session["OrdProduct"].ToString()); Session["idProduct"] = ""; Session["OrdProduct"] = ""; int sl = 0; var Sopping = (clsGiohang)Session["giohang"]; if (Sopping == null) { Sopping = new clsGiohang(); } if (Kiemtra(id) == 1) { for (int i = 0; i < Sopping.CartItem.Count; i++) { if (Sopping.CartItem[i].id == id) { Sopping.CartItem[i].Ord = Sopping.CartItem[i].Ord + Ord; Sopping.CartItem[i].SumPrice = Sopping.CartItem[i].Ord * Sopping.CartItem[i].Price; } tongtien += Sopping.CartItem[i].SumPrice; } Sopping.CartTotal = tongtien; } else { var Sanpham = new clsProduct(); Sanpham.id = id; var Product = db.tblProducts.Find(id); Sanpham.Price = float.Parse(Product.Price.ToString()); Sanpham.Ord = Ord; Sanpham.Name = Product.Name; Sanpham.SumPrice = Sanpham.Price * Sanpham.Ord; Sanpham.Tag = Product.Tag; Sopping.CartItem.Add(Sanpham); for (int i = 0; i < Sopping.CartItem.Count; i++) { tongtien += Sopping.CartItem[i].SumPrice; } Sopping.CartTotal = tongtien; } Session["giohang"] = Sopping; sl = Sopping.CartItem.Count; var s = (clsGiohang)Session["giohang"]; Session["soluong"] = sl; return(RedirectToAction("OrderIndex", "Order")); }
public ActionResult Create(string idp, string ord) { int id = int.Parse(idp); int Ord = int.Parse(ord); int sl = 0; var Sopping = (clsGiohang)Session["giohang"]; if (Sopping == null) { Sopping = new clsGiohang(); } if (Kiemtra(id) == 1) { for (int i = 0; i < Sopping.CartItem.Count; i++) { if (Sopping.CartItem[i].id == id) { Sopping.CartItem[i].Ord = Sopping.CartItem[i].Ord + Ord; Sopping.CartItem[i].SumPrice = Sopping.CartItem[i].Ord * Sopping.CartItem[i].Price; } tongtien += Sopping.CartItem[i].SumPrice; } Sopping.CartTotal = tongtien; } else { var Sanpham = new clsProduct(); Sanpham.id = id; var Product = db.tblProducts.Find(id); Sanpham.Price = int.Parse(Product.PriceSale.ToString()); Sanpham.Ord = Ord; Sanpham.Name = Product.Name; Sanpham.SumPrice = Sanpham.Price * Sanpham.Ord; Sanpham.Tag = Product.Tag; Sanpham.Images = Product.ImageLinkThumb; Sopping.CartItem.Add(Sanpham); for (int i = 0; i < Sopping.CartItem.Count; i++) { tongtien += Sopping.CartItem[i].SumPrice; } Sopping.CartTotal = tongtien; } Session["giohang"] = Sopping; sl = Sopping.CartItem.Count; var s = (clsGiohang)Session["giohang"]; Session["soluong"] = sl; var giohang = (clsGiohang)Session["giohang"]; string chuoi = ""; chuoi += " <div id=\"OrderPopup\">"; chuoi += "<a href=\"javascript:void(0)\" title=\"\" class=\"close_popup\" onclick=\"close_popup()\"></a>"; chuoi += "<table align=\"left\" cellpadding=\"2\" >"; chuoi += "<tr class=\"top\">"; chuoi += "<td class=\"Name\">Tên sản phẩm</td>"; chuoi += "<td class=\"Price\">Đơn giá</td>"; chuoi += "<td class=\"Ord\">SL</td>"; chuoi += "<td class=\"PriceSale\">Thành tiền</td>"; chuoi += "</tr>"; chuoi += "</table>"; chuoi += "<div id=\"Content_OrderPopup\">"; chuoi += "<table align=\"left\" cellpadding=\"2\">"; for (int i = 0; i < giohang.CartItem.Count; i++) { chuoi += "<tr class=\"row" + giohang.CartItem[i].id + "\" >"; chuoi += "<td class=\"Name\" >"; chuoi += "<a href=\"/Product/" + giohang.CartItem[i].Tag + "-" + giohang.CartItem[i].id + ".aspx\" id=\"UpdateOrd" + giohang.CartItem[i].id + "\"><img src=\"" + giohang.CartItem[i].Images + "\" alt=\"" + giohang.CartItem[i].Name + "\" title=\"" + giohang.CartItem[i].Name + "\" /></a>"; chuoi += "<a href=\"/Product/" + giohang.CartItem[i].Tag + "-" + giohang.CartItem[i].id + ".aspx\" class=\"Namepd\">" + giohang.CartItem[i].Name + "</a>"; chuoi += "<a href=\"javascript:void(0)\" title=\"\" class=\"Delete\" onclick=\"javascript:return DeleteOrder(" + giohang.CartItem[i].id + ")\">Xóa</a>"; chuoi += "</td>"; chuoi += "<td class=\"Price\"><span>" + string.Format("{0:#,#}", giohang.CartItem[i].Price) + " vnđ</span></td>"; chuoi += "<td class=\"Ord\"><input type=\"number\" name=\"Ord\" class=\"txtOrd" + giohang.CartItem[i].id + "\" value=\"" + giohang.CartItem[i].Ord + "\" onchange=\"javascript:return UpdateOrd(" + giohang.CartItem[i].id + ")\" /></td>"; chuoi += "<td class=\"PriceSale\"><span id=\"Gia" + giohang.CartItem[i].id + "\">" + string.Format("{0:#,#}", giohang.CartItem[i].SumPrice) + " vnđ</span></td>"; chuoi += "</tr>"; } chuoi += "</table>"; chuoi += "</div>"; chuoi += " <div class=\"Sum\">"; chuoi += " <div class=\"LeftSUM\">"; chuoi += " <span>Bạn có <span class=\"count\">" + giohang.CartItem.Count + "</span> sản phẩm trong giỏ hàng</span>"; chuoi += " </div>"; chuoi += " <div class=\"RightSUM\">"; chuoi += " <span class=\"Sum1\">Tổng cộng : <span class=\"tt\">" + string.Format("{0:#,#}", giohang.CartTotal) + "</span> vnđ </span>"; chuoi += " <span class=\"Sum2\">Thành tiền: <span class=\"tt\">" + string.Format("{0:#,#}", giohang.CartTotal) + "</span> vnđ </span>"; chuoi += " </div>"; chuoi += "</div>"; chuoi += "<div class=\"OrderNows\">"; chuoi += " <a href=\"javascript:void(0)\" title=\"\" onclick=\"close_popup()\" class=\"nexorder\">Tiếp tục mua hàng</a>"; chuoi += " <a href=\"/Order/OrderIndex\" title=\"\" class=\"noworder\">Tiến hành đặt hàng</a>"; chuoi += " </div>"; chuoi += "</div>"; var result = chuoi; return(Json(new { result = result, sl = sl })); }
public ActionResult OrderIndex() { int id; int Ord; int idMenu; if (Session["idProduct"] != "" && Session["OrdProduct"] != "" && Session["idMenu"] != "") { id = int.Parse(Session["idProduct"].ToString()); Ord = int.Parse(Session["OrdProduct"].ToString()); idMenu = int.Parse(Session["idMenu"].ToString()); Session["idProduct"] = ""; Session["OrdProduct"] = ""; Session["idMenu"] = ""; int sl = 0; var Sopping = (clsGiohang)Session["giohang"]; if (Sopping == null) { Sopping = new clsGiohang(); } if (Kiemtra(id) == 1) { for (int i = 0; i < Sopping.CartItem.Count; i++) { if (Sopping.CartItem[i].id == id) { Sopping.CartItem[i].Ord = Sopping.CartItem[i].Ord + Ord; Sopping.CartItem[i].SumPrice = Sopping.CartItem[i].Ord * Sopping.CartItem[i].Price; } tongtien += Sopping.CartItem[i].SumPrice; } Sopping.CartTotal = tongtien; } else { var Sanpham = new clsProduct(); Sanpham.id = id; var Product = db.tblProducts.Find(id); Sanpham.Price = float.Parse(Product.Price.ToString()); Sanpham.Ord = Ord; Sanpham.Name = Product.Name; Sanpham.idMenu = idMenu; Sanpham.SumPrice = Sanpham.Price * Sanpham.Ord; Sanpham.Tag = Product.Tag; Sopping.CartItem.Add(Sanpham); for (int i = 0; i < Sopping.CartItem.Count; i++) { tongtien += Sopping.CartItem[i].SumPrice; } Sopping.CartTotal = tongtien; } Session["giohang"] = Sopping; sl = Sopping.CartItem.Count; var s = (clsGiohang)Session["giohang"]; Session["soluong"] = sl; } var giohang = (clsGiohang)Session["giohang"]; if (Session["Status"] != "") { ViewBag.Status = Session["Status"]; Session["Status"] = ""; } ViewBag.url = Session["Url"].ToString(); ViewBag.Title = "<title>Giỏ hàng của bạn</title>"; ViewBag.Description = "<meta name=\"description\" content=\" Giỏ hàng đặt hàng máy lọc nước Sơn Hà dành cho khách hàng mua sản phẩm\"/>"; ViewBag.Keyword = "<meta name=\"keywords\" content=\"Giỏ hàng của bạn\" /> "; return(View(giohang)); }