public static void deleteItemFromCart(string itemNum, string empNum) { UniversityStoreEntities context = new UniversityStoreEntities(); var q = from x in context.RequestStationaryCarts where x.EmployeeNumber == empNum && x.ItemCode == itemNum select x; RequestStationaryCart rc = q.First <RequestStationaryCart>(); context.DeleteObject(rc); context.SaveChanges(); }
public static void addToCart(string itemNumber, int qty, string empNumber) { UniversityStoreEntities context = new UniversityStoreEntities(); RequestStationaryCart c = new RequestStationaryCart(); c.EmployeeNumber = empNumber; c.ItemCode = itemNumber; c.Quantity = Convert.ToInt32(qty); context.AddToRequestStationaryCarts(c); context.SaveChanges(); }
protected void btnAdd_Click(object sender, EventArgs e) { List <String> itemNumberList = new List <string>(); List <int> qtyList = new List <int>(); cartList = RequestStationaryControler.getEmployeeCart(empNo); //hard code ArrayList CheckBoxArray = (ArrayList)ViewState["CheckBoxArray"]; Dictionary <int, string> qtyArray = (Dictionary <int, string>)ViewState["QtyArray"]; bool isExist = false; bool isCheck = false; bool isZero = false; lblError.Text = ""; if (txtSearchItem.Text != "") { grdItemList.DataSource = RequestStationaryControler.displaySerachResults(txtSearchItem.Text); } else { grdItemList.DataSource = RequestStationaryControler.acceptAllProducts(); } grdItemList.AllowPaging = false; this.DataBind(); for (int index = 0; index < CheckBoxArray.Count; index++) { CheckBox chk = (CheckBox)grdItemList.Rows[Convert.ToInt32(CheckBoxArray[index].ToString()) - 1].Cells[4].FindControl("chkSelectItem"); chk.Checked = true; TextBox txt = (TextBox)grdItemList.Rows[Convert.ToInt32(CheckBoxArray[index].ToString()) - 1].Cells[3].FindControl("txtQuantity"); txt.Text = qtyArray[Convert.ToInt32(CheckBoxArray[index].ToString())]; } for (int i = 0; i < grdItemList.Rows.Count; i++) { CheckBox chk = (CheckBox)grdItemList.Rows[i].Cells[4].FindControl("chkSelectItem"); if (chk.Checked) { Label lbl = (Label)grdItemList.Rows[i].Cells[0].FindControl("lblItemNumber"); TextBox txt = (TextBox)grdItemList.Rows[i].Cells[3].FindControl("txtQuantity"); for (int j = 0; j < cartList.Count; j++) { RequestStationaryCart cart = (RequestStationaryCart)cartList[j]; if (lbl.Text == cart.ItemCode) { if (lblError.Text == "") { lblError.Text += "Item Code " + lbl.Text; } else { lblError.Text += " , " + lbl.Text; } isExist = true; } } if (isExist == false) { itemNumberList.Add(lbl.Text); if (txt.Text == "") { qtyList.Add(0); } else { qtyList.Add(Convert.ToInt32(txt.Text)); } } isCheck = true; } } if (isExist == false) { for (int i = 0; i < qtyList.Count; i++) { if (qtyList[i] == 0) { lblError.Text += itemNumberList[i].ToString() + "'s should not be '0'!<br>"; lblError.ForeColor = System.Drawing.Color.Red; isZero = true; } } if (isZero == false) { RequestStationaryControler.addSelectedItemsToCart(itemNumberList.ToArray(), qtyList.ToArray(), empNo); } if (isCheck == true && isZero == false) { lblError.Text = " Your requested items are already added to cart"; lblError.ForeColor = System.Drawing.ColorTranslator.FromHtml("#4582ec"); } else if (isCheck == false) { lblError.Text = "Please select items to add"; lblError.ForeColor = System.Drawing.Color.Red; } } else { lblError.Text += " already requested !"; lblError.ForeColor = System.Drawing.Color.Red; } cartList = RequestStationaryControler.getEmployeeCart(empNo); //to calculate the view cart count btnViewCart.Text = "View Cart ( " + cartList.Count + " ) "; grdItemList.AllowPaging = true; this.DataBind(); }