public ActionResult Index() { //this method will get shopping cart details and return the shooping cart view decimal? Subtotal = 0; int Count = 0; CartServices service = new CartServices(); Cart cart = new Cart(); if (Session[SessionConstants.SESSION_CONTEXT_INSTANCE] != null) { //get cart details for the logged in user's userid User user = (User)(Session[SessionConstants.SESSION_CONTEXT_INSTANCE]); List <CartItem> list = service.GetCartItems(user.UserId); //calculate count and subtotal of the cart if (list != null) { foreach (var item in list) { Count = Count + item.Qty; Subtotal = Subtotal + (item.Qty * item.Price); } } cart.CartItemList = list; cart.Count = Count; cart.SubTotal = Subtotal; return(View(cart)); } else { cart.CartItemList = new List <CartItem>(); return(View(cart)); } }
public HeaderDetails CreateSessionModel(int UserId, String FullName) { //this method will creating a datamodel(which contains wishlist and cart details of logged user) decimal? Subtotal = 0; int Count = 0; CartServices service = new CartServices(); HeaderDetails details = new HeaderDetails(); List <CartItem> CartItemlist = new List <CartItem>(); details.cart.CartItemList = service.GetCartItems(UserId); details.wishListCount = service.GetWishListItems(UserId).Count(); details.FullName = FullName; //calculate cart subtotal and count if (details.cart.CartItemList != null) { foreach (var item in details.cart.CartItemList) { Count = Count + item.Qty; Subtotal = Subtotal + (item.Qty * item.Price); } } details.cart.Count = Count; details.cart.SubTotal = Subtotal; return(details); }
public ActionResult CartItems() { if (HttpContext.Request.Cookies.Get("myaccount") != null) { HttpCookie rqstCookie = HttpContext.Request.Cookies.Get("myaccount"); var memberDataObj = FormsAuthentication.Decrypt(rqstCookie.Value); var memberData = JsonConvert.DeserializeObject <Member>(memberDataObj.UserData); CartServices cartServices = new CartServices(); OrderDetail [] products = cartServices.GetCartItems(memberData.MemberID); return(Json(products, JsonRequestBehavior.AllowGet)); } else { return(null); } }
public IEnumerable <Cart> GetCart(string id) { return(cartService.GetCartItems(id)); }
public virtual JsonResult AddProductToCart_Details(int productId, int shoppingCartTypeId, int qty) { if (Session[SessionConstants.SESSION_CONTEXT_INSTANCE] != null) { CartServices service = new CartServices(); //check seesion is available, only logged in users can add to cart/wishlist User user = (User)(Session[SessionConstants.SESSION_CONTEXT_INSTANCE]); //add to shopping cart if (shoppingCartTypeId == 1) { CartItem item = new CartItem(); int cartId = 0; item.Id = productId; item.UserId = user.UserId; item.Qty = qty; List <CartItem> list = service.GetCartItems(item.UserId); //check item is already exists in cart foreach (var cartItem in list) { if (cartItem.Id == item.Id) { cartId = cartItem.cartId; break; } } if (cartId > 0) { //add new items to the cart int id = service.EditCartItems(item); return(Json(new { Status = true, Message = "Succesfully updated the shopping cart..." }, JsonRequestBehavior.AllowGet)); } else { //update the cart with new quantitiesS int id = service.AddCartItems(item); return(Json(new { Status = true, Message = "Succesfully added to the shopping cart..." }, JsonRequestBehavior.AllowGet)); } } //add to wishlist else { wishListItem item = new wishListItem(); item.UserId = user.UserId; item.Id = productId; List <wishListItem> list = service.GetWishListItems(item.UserId); //check item is already exists in wishlist foreach (var wishItem in list) { if (wishItem.Id == item.Id) { //if already item exists alret user return(Json(new { Status = true, Message = "Item already exists in wishlist..." }, JsonRequestBehavior.AllowGet)); } } //if item not in wishlist,add item to the user's wishlist int id = service.AddWishListItems(item); return(Json(new { Status = true, Message = "Succesfully added to the wishlist..." }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { Status = false, Message = "Not logged-in..." }, JsonRequestBehavior.AllowGet)); } }