protected void updateCartButton_Click(object sender, EventArgs e) { User user = (User)Session[Constant.Keys.AUTH]; int id = Int32.Parse(Request.QueryString["id"]), Quantity = 0; string messageError = ""; messageError = CartController.update(updateCartQuantityTxt.Text, id, user.ID); if (messageError != "") { labelErrorUpdateCart.Text = messageError; } else { Quantity = int.Parse(updateCartQuantityTxt.Text); Product product = ProductHandler.get(id); if (Quantity == 0) { CartHandler.remove(user.ID, id); } else { CartHandler.updateNewQuantity(user.ID, id, Quantity); } var redirecTo = Constant.Routes.VIEW_CART_ROUTE; Response.Redirect(redirecTo); } }
protected void addToCartButton_Click(object sender, EventArgs e) { int id = Int32.Parse(Request.QueryString["id"]), Quantity = 0; string messageError = ""; messageError = CartController.Add(addToCartQuantityTxt.Text, id); if (messageError != "") { labelErrorAddToCart.Text = messageError; } else { User user = (User)Session[Constant.Keys.AUTH]; Quantity = int.Parse(addToCartQuantityTxt.Text); Product product = ProductHandler.get(id); if (CartHandler.get(user.ID, product.ID) != null) { CartHandler.updateQuantity(user.ID, id, Quantity); } else { CartInformation currentProduct = new CartInformation(); currentProduct.ID = product.ID; currentProduct.Name = product.Name; currentProduct.Price = product.Price; currentProduct.Quantity = Quantity; currentProduct.SubTotal = currentProduct.Quantity * currentProduct.Price; CartHandler.add(user.ID, id, Quantity); } var redirecTo = Constant.Routes.VIEW_CART_ROUTE; Response.Redirect(redirecTo); } }
public static string CheckInsert(int userId, string str_productId, string str_quantity) { string response = ""; if (str_productId == "") { response = "Product ID must be filled"; } else if (str_quantity == "") { response = "Quantity must be filled"; } else { int productId = int.Parse(str_productId); int quantity = int.Parse(str_quantity); if (!CartHandler.InsertCart(userId, productId, quantity)) { response = "Failed to order product"; } } return(response); }
public static String doAddCart(int qty, int medicineId, int userId) { Cart cp = CartHandler.getCartMedicine(medicineId, userId); int medicineStock = MedicineHandler.getMedicineById(medicineId).Stock; if (qty < 1) { return("Qty must be more than 0"); } if (cp == null) { if (qty > medicineStock) { return("Qty can't be more than available stock"); } CartHandler.createCartMedicine(userId, medicineId, qty); return(""); } else { int currCartStock = cp.Quantity; int requetedStock = currCartStock + qty; if (requetedStock > medicineStock) { return("Qty must be less than or equals to medicine stocks"); } CartHandler.updateCartMedicineQty(medicineId, userId, requetedStock); return(""); } }
public static String DoAddCart(int qty, int productId, int userId) { Cart cp = CartHandler.getCartProduct(productId, userId); int productStock = ProductHandler.getProductByID(productId).Stock; if (qty < 1) { return("Quantity must be more than 0"); } if (cp == null) { if (qty > productStock) { return("Quantity can't be more than available stock"); } CartHandler.createCartProduct(userId, productId, qty); return(""); } else { int currCartStock = cp.Quantity; int totalRequestStock = currCartStock + qty; if (totalRequestStock > productStock) { return("Quantity must be less than or equals to product stocks"); } CartHandler.updateCartProductQty(productId, userId, totalRequestStock); return(""); } }
protected void Page_Load(object sender, EventArgs e) { BetaDB db = new BetaDB(); carthandler = new CartHandler(); if (!IsPostBack) { CartDetails(); } if (carthandler.GetCount() == 0) { cartCalculation.Visible = false; } //else //{ // cartCalculation.Visible = true; //} if (!Page.IsPostBack) { lblCartTotal.Text = totalPrice.ToString() + "$"; double tax = (((double)totalPrice * 15) / 100); lbltax.Text = tax.ToString(); lbldelivery.Text = NicePayment.PaymentHandler._fixedShipping.ToString() + "$"; double grandtotal = totalPrice + Convert.ToDouble(lbltax.Text) + NicePayment.PaymentHandler._fixedShipping; lbltax.Text += "$"; lblGrandCartTotal.Text = grandtotal.ToString() + "$"; } }
public static Response UpdateCart(int userId, int productId, int qty) { int n = 0; bool isNumeric = int.TryParse(qty.ToString(), out n); Product p = ProductHandler.GetProduct(productId); if (isNumeric == false) { return(new Response(false, "must be numeric")); } else if (qty > p.Stock) { return(new Response(false, "must be less than or equals to current stock")); } else if (qty < 0) { return(new Response(false, "input field cannot be inputted below 0")); } else { CartHandler.UpdateCart(userId, productId, qty); return(new Response(true)); } }
public static string Add(String Quantity, int ID) { string error = ""; int QuantityProduct = 0; bool flag = true; try { QuantityProduct = int.Parse(Quantity); } catch (Exception ex) { if (ex != null) { flag = false; error = "Input quantity must be a number"; } } if (flag) { if (int.Parse(Quantity) <= 0) { error = "Quantity must be more than 0"; } else if (int.Parse(Quantity) > ProductHandler.getStock(ID)) { error = "Quantity must be less than or equals to current stock"; } else if (int.Parse(Quantity) + CartHandler.getTotalQuantity(ID) > ProductHandler.getStock(ID)) { error = "The inputted quantity and the reserved quantity in other carts combined altogether must not exceed the selected product’s current stock"; } } return(error); }
protected void AddCartBtn_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["ID"]); int userId = Convert.ToInt32(((User)Session["auth_user"]).Id.ToString()); int qty = Convert.ToInt32(TxtQty.Text); Product products = ProductRepo.GetProductByID(id); bool isExist = CartHandler.isExist(id, userId); if (isExist == true) { Cart carts = CartRepo.getCartbyProductIdAndUserId(id, userId); qty = qty + carts.Quantity; } if (qty > products.Stock) { LblError.Text = "Sorry, This Product Stock is just " + products.Stock; } else { if (isExist == false) { CartRepo.doInsertProductToCart(id, userId, qty); } else { CartRepo.addQtyProduct(id, userId, qty); } Response.Redirect("./ViewProduct.aspx"); } }
public void CartCount() { if (carthandler == null) { carthandler = new CartHandler(); } lblCartNumber.Text = carthandler.GetCount().ToString() == "0" ? "": carthandler.GetCount().ToString(); }
protected void gvCart_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "RemoveItem") { CartHandler.RemoveItemFromCart(HttpContext.Current.User.Identity.Name, e.CommandArgument.ToString()); gvCart.DataSource = CartHandler.GetCartByUser(HttpContext.Current.User.Identity.Name); gvCart.DataBind(); } }
public ActionResult Confirm() { var cart = GetCart(); OrderHandler.ConfirmOrder(ref cart); CartHandler.SaveCart(cart); return(View("Confirm")); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { gvCart.DataSource = CartHandler.GetCartByUser(HttpContext.Current.User.Identity.Name); gvCart.DataBind(); LbCount.Text = BusinessLayer.CartHandler.GetCartItemCount(HttpContext.Current.User.Identity.Name).ToString(); } }
private void SetLabelText(int productId) { Product p = ProductHandler.GetProduct(productId); Cart c = CartHandler.GetCart(Int32.Parse(Session["id"].ToString()), productId); prodName.Text = p.Name; prodPrice.Text = p.Price.ToString(); prodStock.Text = p.Stock.ToString(); quantityTxt.Text = c.Quantity.ToString(); }
public static Boolean checkstock(int productID) { Product product = CartHandler.getProductById(productID); if (product.productStock == 0) { return(false); } return(true); }
public static Boolean isTypeExist(int TypeID) { PaymentType pt = CartHandler.getType(TypeID); if (pt == null) { return(false); } return(true); }
public static Boolean isProductExist(int productID) { Product product = CartHandler.getProductById(productID); if (product == null) { return(false); } return(true); }
protected void lblDeletes_Click(object sender, EventArgs e) { int id = Int32.Parse((sender as LinkButton).CommandArgument); User user = (User)Session[Constant.Keys.AUTH]; int ID = id; CartHandler.remove(user.ID, ID); loadData(); lblErrorDeleteViewCart.Text = "Product successfully deleted from your cart"; }
protected void tableProductType_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; int userId = Int32.Parse(Session["id"].ToString()); string productId = tableCart.Rows[index].Cells[2].Text; int id = Int32.Parse(productId); CartHandler.DeleteCart(userId, id); Response.Redirect(Request.RawUrl); }
//public static String doUpdateCart(int qty, int medicineId, int userId) //{ // int medicineStock = MedicineHandler.getMedicineById(medicineId).Stock; // if (qty == 0) // { // CartHandler.deleteCartMedicine(medicineId, userId); // return ""; // } // else if (qty < 1) // { // return "Quantity must be more than 0"; // } // else if (qty > medicineStock) // { // return "Quantity can't be more than available stock"; // } // CartHandler.updateCartMedicineQty(medicineId, userId, qty); // return ""; //} public static String checkout(int userID) { Cart cp = CartHandler.getCartMedicineByUser(userID); if (cp == null) { return("empty"); } CartHandler.checkout(userID); return("success"); }
public static void requestAddToCart(int userId, int productId, int qty) { if (CartHandler.isItemAlreadyExist(userId, productId)) //If there's item that wants to add { CartHandler.updateQtyForExistingItem(userId, productId, qty); } else { CartHandler.createNewCart(userId, productId, qty); } }
public static void removeCart(int productID) { List <Cart> cartlist2 = CartHandler.getCart(); foreach (Cart cart in cartlist2) { if (cart.Quantity == 0) { CartHandler.removeFromCart(productID); } } }
private static bool checkSameProduct(int userId, int shoeId) { CartModel cart = CartHandler.getSpecificProductUserCart(userId, shoeId); if (cart != null) { return(true); } else { return(false); } }
public ActionResult RemoveProduct(int productId = 0) { var cart = GetCart(); CartHandler.ChangeProductCount(productId, 0, cart); var member = PublicUser.GetCurrentUser(); if (member == null || member.MemberId <= 0) { Session[Constants.CartKeyName] = cart; } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
void refresh() { List <Cart> cart = CartHandler.getCart(); var dataSource = cart.Select(x => new { x.productID, x.Quantity }); cartlist2.DataSource = dataSource; cartlist2.DataBind(); }
public static void update(int userid, int productid, int qty) { Cart cart = getCart(productid, userid); if (qty == 0) { CartHandler.delete(cart); } else { CartHandler.update(cart, qty); } }
public static bool deleteCartById(int cartId) { UserCart cart = CartHandler.findCartByID(cartId); if (cart != null) { CartRepository.deleteCart(cart); return(true); } else { return(false); } }
public static void updateCart(int productId, int userId, int qty) { //Cek Dulu cartnya udah ada atau belum Cart carts = getCartByProductIdAndUserId(productId, userId); if (carts == null) { // NULL } else { CartHandler.updateCart(productId, userId, qty); } }
public static void createCart(int productId, int userId, int qty) { //Cek Dulu cartnya udah ada atau belum Cart carts = getCartByProductIdAndUserId(productId, userId); if (carts == null) { CartHandler.doInsertCart(productId, userId, qty); } else { CartHandler.addQtyCartProduct(productId, userId, qty); } }
public static Response InsertCart(int userId, int productId, string quantity) { if (quantity == "" || quantity.All(char.IsDigit) != true) { return(new Response(false, "Quantity cannot be empty or non numeric")); } int _quantity = Int32.Parse(quantity); if (CartHandler.InsertCart(userId, productId, _quantity)) { return(new Response(true, "Product has been added to cart")); } return(new Response(false, "Quantity invalid")); }