public ActionResult AddtoCart(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Products products = db.Products.Find(id); if (products == null) { return(HttpNotFound()); } var userid = User.Identity.GetUserId(); var user = db.Users.Find(userid); var c = new ProductsCart() { Product = products, User = user }; db.Cart.Add(c); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult GioHang() { OrderCart model = new OrderCart(); model.listSanpham = new List <ProductsCart>(); ProductsBLL _getprod = new ProductsBLL(); if (Request.Cookies["shopcard"] != null) { var _list = JsonConvert.DeserializeObject <List <Cart> >(Request.Cookies["shopcard"].Value); List <Products> _listProduct = new List <Products>(); _list.ForEach(p => { var _object = _getprod.ProductById(p.ProductId); if (_object != null) { ProductsCart _cart = new ProductsCart(); _cart.Id = _object.Id; _cart.Name = _object.Name; _cart.Price = _object.Price; _cart.PriceSale = _object.PriceSale; _cart.Url = _object.Url; _cart.Quality = p.Number; _cart.AllPrice = (_object.PriceSale == 0 ? (p.Number * _object.Price) : (p.Number * _object.PriceSale)); model.listSanpham.Add(_cart); } }); model.TamTinh = model.listSanpham.Sum(p => p.AllPrice); model.AllPayment = model.listSanpham.Sum(p => p.AllPrice); } return(View(model)); }
public void Display() { ProductsCart.Display(); this.DoTotal(); PaymentDetails.Display(); Console.WriteLine($"\tSubtotal: ${Subtotal}\n"); Console.WriteLine($"\tSales Tax @{TaxRate * 100}% : ${SalesTax}\n"); Console.WriteLine($"\tGrand Total: ${GrandTotal}\n"); }
public void Update(List <BLOrderDetail> products) { ProductsCart.DataSource = products; ProductsCart.DataBind(); UpdateSumCart(products); if (products == null || products.Count == 0) { ProductError.Text = "there is no products"; //error msg NumOfProducts.Text = ""; TotalPrice.Text = ""; return; } ProductError.Text = ""; }
public void Update(List <BLProduct> products) { ProductsCart.DataSource = products; Session["productsCart"] = products; ProductsCart.DataBind(); UpdateSumCart(products); if (products == null || products.Count == 0) { MSG.Text = "there is no products"; //error msg NumOfProducts.Text = ""; TotalPrice.Text = ""; return; } MSG.Text = ""; }
protected void btnDelete_Command(object sender, CommandEventArgs e) { if (Session["ID"] != null) { int id = Convert.ToInt32(e.CommandArgument); using (AABZContext context = new AABZContext()) { ProductsCart pc = (from p in context.ProductsCarts where p.Id == id select p).FirstOrDefault(); context.ProductsCarts.Remove(pc); context.SaveChanges(); refreshCart(); } } }
protected void removeItem(object sender, CommandEventArgs e) { if (Session["ID"] != null) { int id = Convert.ToInt32(e.CommandArgument); using (AABZContext context = new AABZContext()) { int userId = Convert.ToInt32(Session["ID"]); Model.Cart cart = (from c in context.Carts where c.user_id == userId select c).FirstOrDefault(); ProductsCart pc = (from p in context.ProductsCarts where p.Id == id select p).FirstOrDefault(); cart.products_cart.Remove(pc); context.ProductsCarts.Remove(pc); context.SaveChanges(); } } }
public void Update(List <BLOrderDetailsDB> orderDetails) { List <BLProduct> products = new List <BLProduct>(); if (orderDetails != null) { products.AddRange(orderDetails.Select(detail => BLProduct.GetProductById(detail.productId))); EmptyCart.Visible = true; } ProductsCart.DataSource = products; Session["orderDetails"] = orderDetails; ProductsCart.DataBind(); UpdateSumCart(orderDetails); if (orderDetails == null || orderDetails.Count == 0) { MSG.Text = "there is no products"; //error msg NumOfProducts.Text = ""; TotalPrice.Text = ""; OrderNow.Visible = false; return; } MSG.Text = ""; }