protected void RepeaterOrder_ItemCommand(object source, RepeaterCommandEventArgs e) { string query = string.Empty; int productId = Convert.ToInt32(e.CommandArgument); if (Session["userlogin"] != null) { if (e.CommandName == "btn_decrease") { query = $"Update OrderDetailTemp set quantity-=1 Where userId={id} And productId={productId} And quantity>0 "; } else if (e.CommandName == "btn_increase") { query = $"Update OrderDetailTemp set quantity+=1 Where userId={id} And productId={productId} And quantity>=0 "; } SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["OnShopCenterConnectionString"].ConnectionString); SqlCommand myCommand = new SqlCommand(query, myConn); try { myConn.Open(); myCommand.ExecuteNonQuery(); } catch (Exception) { } finally { myConn.Close(); } } else { if (e.CommandName == "btn_decrease") { OrderDetailsTemps.Find(o => o.ProductId == productId).Quantity -= 1; } else if (e.CommandName == "btn_increase") { OrderDetailsTemps.Find(o => o.ProductId == productId).Quantity += 1; } numItemInCart.Text = OrderDetailsTemps.Count().ToString(); Session["anonimo"] = OrderDetailsTemps; } Response.Redirect("CartPage.aspx"); }
protected void Page_Load(object sender, EventArgs e) { Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-Pt"); if (Session["userlogin"] == null) { if (Session["anonimo"] != null) { OrderDetailsTemps = (List <OrderDetailsTemp>)Session["anonimo"]; lbl_total.Text = OrderDetailsTemps.Sum(o => Convert.ToDecimal((decimal)o.Price * o.Quantity)).ToString("C"); lbl_sub.Text = OrderDetailsTemps.Sum(o => Convert.ToDecimal((decimal)o.Price * o.Quantity)).ToString("C"); numItemInCart.Text = OrderDetailsTemps.Count().ToString(); RepeaterOrder.DataSource = OrderDetailsTemps; RepeaterOrder.DataBind(); } } else { lbl_user.Text = $"Benvido {Session["userlogin"].ToString()}"; btn_login.Text = "Logout"; id = Convert.ToInt32(Session["userId"].ToString()); BindingRepeaterOrder(id); if (Session["userRole"].ToString() == "Reseller") { resellerInfo.Visible = true; } } if (OrderDetailsTemps.Count == 0 || OrderDetailsTemps == null) { btn_checkout.Enabled = false; } }