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); }
// GET: WishList public ActionResult Index() { //this method will get wishlist details and return the wishlist view CartServices service = new CartServices(); if (Session[SessionConstants.SESSION_CONTEXT_INSTANCE] != null) { //get wishlist details for the logged in user's userid User user = (User)(Session[SessionConstants.SESSION_CONTEXT_INSTANCE]); List <wishListItem> list = service.GetWishListItems(user.UserId); return(View(list)); } else { List <wishListItem> list = new List <wishListItem>(); return(View(list)); } }
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)); } }