protected void DeleteButton_Click(object sender, ImageClickEventArgs e) { //Get the reference of the clicked button. ImageButton button = (sender as ImageButton); //Get the command argument string commandArgument = button.CommandArgument; int wishlistid = int.Parse(commandArgument); GalleryEntities1 db = new GalleryEntities1(); var item = new WISHLIST { WishlistId = wishlistid }; db.Entry(item).State = EntityState.Deleted; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", String.Format("Item with id {0} no longer exists in the database.", wishlistid)); } }
protected void btnAddToCart_Click(object sender, EventArgs e) { //Get the reference of the clicked button. Button button = (sender as Button); //Get the command argument string[] commandArgument = button.CommandArgument.ToString().Split(';'); int wishlistId = Convert.ToInt32(commandArgument[0]); int productId = Convert.ToInt32(commandArgument[1]); //System.Diagnostics.Debug.WriteLine(wishlistId + "," + productId); ShoppingCart sc = new ShoppingCart(); sc.AddToCart(productId); GalleryEntities1 db = new GalleryEntities1(); var item = new WISHLIST { WishlistId = wishlistId }; db.Entry(item).State = EntityState.Deleted; try { db.SaveChanges(); Response.Redirect("~/Wishlistaspx.aspx"); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", String.Format("Item with id {0} no longer exists in the database.", wishlistId)); } }
protected void btnWishlist_Click(object sender, EventArgs e) { bool loginStatus = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated; if (loginStatus) { GalleryEntities1 _db = new GalleryEntities1(); int productID = Convert.ToInt32(Request.QueryString["ProductID"]); Guid userId = (Guid)Membership.GetUser().ProviderUserKey; var existingItem = from w in _db.WISHLISTs where w.ProductId == productID && w.UserId == userId select w; if (existingItem.Any()) { successAdd.Style["display"] = "none"; failedAdd.Style["display"] = "block"; System.Diagnostics.Debug.WriteLine("exist"); } else { WISHLIST item = new WISHLIST(); item.ProductId = productID; item.UserId = userId; if (ModelState.IsValid) { // Save changes here _db.WISHLISTs.Add(item); _db.SaveChanges(); successAdd.Style["display"] = "block"; failedAdd.Style["display"] = "none"; } System.Diagnostics.Debug.WriteLine("not exist"); } } else { MasterPage masterPage = this.Master as MasterPage; ModalPopupExtender ModalPopupExtender1 = (ModalPopupExtender)masterPage.FindControl("ModalPopupExtender1"); ModalPopupExtender1.Show(); } }