public ActionResult Checkout(string receiver, string phone, string address) { User user = (User)Session["USER"]; if (user != null) { CartObj cart = (CartObj)Session["CART"]; if (cart != null) { DateTime date = DateTime.Now; OrderDAO daoOrder = new OrderDAO(); OrderDetailsDAO daoDetails = new OrderDetailsDAO(); Order order = new Order() { phone = phone, receiver = receiver, addressShip = address, username = user.username, orderDate= date}; daoOrder.Add(order); int currentID = daoOrder.GetCurrentOrderID(); foreach(var item in cart.cart) { OrderDetail details = new OrderDetail() { orderID = currentID, phoneID = item.Key.phoneID, price = item.Key.price, quantity = item.Value, discount = item.Key.discount }; daoDetails.Add(details); PhoneDAO daoPhone = new PhoneDAO(); daoPhone.UpdateQuantity(item.Value,item.Key.phoneID); } Session["CART"] = null; } } return RedirectToAction("Index", "Home", new { area = "" }); }
public ActionResult RemoveCart(string phoneID) { CartObj cart = (CartObj)Session["CART"]; if (cart == null) { cart = new CartObj(); } cart.RemoveCart(phoneID); Session["CART"] = cart; return(View("Index")); }
public JsonResult AddToCart(string phoneID) { CartObj cart = (CartObj)Session["CART"]; if (cart == null) { cart = new CartObj(); } cart.AddToCart(phoneID); Session["CART"] = cart; List <dynamic> x = new List <dynamic>(); x.Add(cart.cart.Count); x.Add(cart.total); return(Json(x)); }
public JsonResult AddToCartWithValue(string phoneID, int value) { PhoneDAO dao = new PhoneDAO(); Phone p = dao.GetPhone(phoneID); CartObj cart = (CartObj)Session["CART"]; if (cart == null) { cart = new CartObj(); } cart.AddToCart(phoneID, value); Session["CART"] = cart; List <dynamic> x = new List <dynamic>(); x.Add(cart.cart.Count); x.Add(cart.total); x.Add(p.quantity - cart.cart[p]); return(Json(x)); }
public JsonResult UpdateCart(string phoneID, int value) { PhoneDAO dao = new PhoneDAO(); Phone phone = dao.GetPhone(phoneID); CartObj cart = (CartObj)Session["CART"]; if (cart == null) { cart = new CartObj(); } cart.UpdateCart(phoneID, value); Session["CART"] = cart; List <dynamic> x = new List <dynamic>(); x.Add(cart.cart.Count); x.Add(cart.total); x.Add(cart.cart[phone] * phone.price); return(Json(x)); }