public ActionResult GetTotalItemsInCart([DataSourceRequest]DataSourceRequest request) { string message; CartHandler ch = new CartHandler(); Cart c = ch.GetUserCart(out message); try { if (c == null) { c = new Cart(); c.TotalItems = 0; c.Message = message; c.IsValid = false; } else { c.CartItems = ch.GetCartItems(c.CartID); } } catch (Exception ex) { logger.Fatal(ex); } return Json(new { success = true, Cart = c }, JsonRequestBehavior.AllowGet); }
public ActionResult CartItems_Read([DataSourceRequest] DataSourceRequest request) { string message; CartHandler ch = new CartHandler(); Cart c = ch.GetUserCart(out message); if (c != null) { var result = productHandler.GetCartProducts(c.CartID); if (result == null || !result.Any()) return RedirectToAction("CartIsEmpty"); else return Json(result.ToDataSourceResult(request)); } else { return RedirectToAction("CartIsEmpty"); } }
public ActionResult GetCartItemsSummary([DataSourceRequest]DataSourceRequest request) { string message; CartHandler ch = new CartHandler(); Cart c = ch.GetUserCart(out message); IEnumerable<CartItems> CartItemSummary = new List<CartItems>(); if (c != null) { string sql = string.Format(@" select CartID,p.ProductName,sum(Quantity) as Quantity,max(Price) as Price, 0 as Shipping from dbo.CartItems ci inner join amz.Products p on ci.ProductID = p.ProductID where CartID = {0} group by CartID,ProductName ", c.CartID); CartItemSummary = ch.GetCartItemsSummary(sql); } return Json(new { success = true, CartItemSummary = CartItemSummary }, JsonRequestBehavior.AllowGet); }
public ActionResult SetCartProcessed([DataSourceRequest]DataSourceRequest request) { CartHandler ch = new CartHandler(); string message; Cart c = ch.GetUserCart(out message); ch.SetCartProcessed(c.CartID, out message); return Json(new { success = true, message = "Check out completed." }, JsonRequestBehavior.AllowGet); }
public ActionResult RemoveItemFromCart([DataSourceRequest]DataSourceRequest request, int productID) { CartHandler ch = new CartHandler(); string message; Cart c = ch.GetUserCart(out message); if (c != null) { ch.RemoveCartItem(c.CartID, productID); } return Json(new { success = true, message = string.Format("product id is {0}", productID) }, JsonRequestBehavior.AllowGet); }
public ActionResult AddItemToCart([DataSourceRequest]DataSourceRequest request, int productID, decimal unitPrice, int quantity, bool addToExisting) { CartHandler ch = new CartHandler(); string message; Cart c = ch.GetUserCart(out message); if (c != null) { ch.AddCartItem(c.CartID, productID, quantity, unitPrice, addToExisting); } return Json(new { success = true, message = string.Format("product id is {0}", productID) }, JsonRequestBehavior.AllowGet); }