protected void imbBtnCheckout_Click(object sender, ImageClickEventArgs e) { WishListTableAdapters.WishListDSTableAdapter wlTA = new WishListTableAdapters.WishListDSTableAdapter(); IEnumerator<WishList.WishListDSRow> wishLists = wlTA.GetWishListForUser(LoggedInUser.UserId).GetEnumerator(); while (wishLists.MoveNext()) { ShoppingTrolley.Web.Objects.Product product = ShoppingTrolley.Web.Objects.Product.LoadCompleteProduct(wishLists.Current.product_id); if (!wishLists.Current.Isproduct_detail_idNull()) { ShoppingCart.AddProductDetail(product, wishLists.Current.product_detail_id, wishLists.Current.version_id,wishLists.Current.quantity); } else ShoppingCart.AddProductVersion(product, wishLists.Current.version_id, wishLists.Current.quantity); } if (GetWishList().Count == 0) { SetErrorMessage("Please select alteast one item before checking out"); } else { if (LoggedInUser == null) { RedirectToLogin(); } else { Response.Redirect("~/pages/AccountAddress.aspx"); } } }
protected void rptItems_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName.Equals("Remove")) { List<ShoppingItem> trolley = GetShoppingTrolley(); trolley.RemoveAt(int.Parse(e.CommandArgument.ToString())); Session[WebConstants.Session.TROLLEY] = trolley; BindRepeater(); } else if (e.CommandName.Equals("Save")) { SimplicityCommLib.DataSets.Common.Users.UsersRow user = Authenticate(); if (user != null) { int index = int.Parse(e.CommandArgument.ToString()); ShoppingItem currentItem = GetShoppingTrolley()[index]; //Save record for current user WishListTableAdapters.WishListDSTableAdapter ta = new WishListTableAdapters.WishListDSTableAdapter(); IEnumerator<WishList.WishListDSRow> wishListRows = null; if (currentItem.ProductDetail != null) { wishListRows = ta.GetWishListForUserByProductId(user.UserId, currentItem.Product.ProductId, currentItem.ProductDetail.product_detail_id, currentItem.ProductVersion.version_id).GetEnumerator(); } else { wishListRows = ta.GetWishListForUserByProductId(user.UserId, currentItem.Product.ProductId, null, currentItem.ProductVersion.version_id).GetEnumerator(); } if (wishListRows.MoveNext()) { wishListRows.Current.quantity += currentItem.Quantity; ta.Update(wishListRows.Current); } else { Nullable<int> versionId = null; if (currentItem.ProductVersion != null) versionId = currentItem.ProductVersion.version_id; Nullable<int> productDetailId = null; if (currentItem.ProductDetail != null) productDetailId = currentItem.ProductDetail.product_detail_id; ta.Insert(user.UserId, currentItem.Product.ProductId, versionId, productDetailId, currentItem.Quantity, currentItem.DurationInMonths); } GetShoppingTrolley().RemoveAt(index); SetInfoMessage("Item added to your wishlist"); BindRepeater(); } else { RedirectToLogin(); } } }
protected void rptItems_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName.Equals("Remove")) { int productWishListId = int.Parse(e.CommandArgument.ToString()); WishListTableAdapters.WishListDSTableAdapter ta = new WishListTableAdapters.WishListDSTableAdapter(); ta.Delete(productWishListId); BindRepeater(); ta.Dispose(); } else if (e.CommandName.Equals("Save")) { if (LoggedInUser != null) { WishList.WishListDSRow wishList = null; int wishListId = int.Parse(e.CommandArgument.ToString()); WishListTableAdapters.WishListDSTableAdapter ta = new WishListTableAdapters.WishListDSTableAdapter(); IEnumerator<WishList.WishListDSRow> wishListRowIterator = ta.GetWishListById(wishListId).GetEnumerator(); if (wishListRowIterator.MoveNext()) wishList = wishListRowIterator.Current; if (wishList != null) { List<ShoppingItem> trolleyItems = ((List<ShoppingItem>)Session[WebConstants.Session.TROLLEY]); bool added = false; if (trolleyItems == null) { trolleyItems = new List<ShoppingItem>(); added = true; ShoppingTrolley.Web.Objects.Product product = ShoppingTrolley.Web.Objects.Product.LoadCompleteProduct(wishList.product_id); if (!wishList.Isproduct_detail_idNull()) { ShoppingCart.AddProductDetail(product, wishList.product_detail_id, wishList.version_id,wishList.quantity); } else ShoppingCart.AddProductVersion(product, wishList.version_id,wishList.quantity); } foreach (ShoppingItem item in trolleyItems) { if (wishList.product_id == item.Product.ProductId) { if (!wishList.Isproduct_detail_idNull() && item.ProductDetail != null && item.ProductDetail.product_detail_id == wishList.product_detail_id) { item.Quantity++; added = true; break; } } } if (!added) { ShoppingTrolley.Web.Objects.Product product = ShoppingTrolley.Web.Objects.Product.LoadCompleteProduct(wishList.product_id); if (!wishList.Isproduct_detail_idNull()) { ShoppingCart.AddProductDetail(product, wishList.product_detail_id, wishList.version_id,wishList.quantity); } else ShoppingCart.AddProductVersion(product, wishList.version_id, wishList.quantity); } ta.Delete(wishListId); BindRepeater(); } SetInfoMessage("Item added to your trolley"); } } }
List<ShoppingItem> GetWishList() { List<ShoppingItem> shoppingItems = new List<ShoppingItem>(); if (LoggedInUser != null) { WishListTableAdapters.WishListDSTableAdapter ta = new WishListTableAdapters.WishListDSTableAdapter(); IEnumerator<WishList.WishListDSRow> wishLists = ta.GetWishListForUser(LoggedInUser.UserId).GetEnumerator(); while (wishLists.MoveNext()) { shoppingItems.Add(ShoppingItem.Load(wishLists.Current)); } } return shoppingItems; }