Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 4
0
        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("");
            }
        }
Ejemplo n.º 6
0
        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() + "$";
            }
        }
Ejemplo n.º 7
0
        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));
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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");
            }
        }
Ejemplo n.º 10
0
 public void CartCount()
 {
     if (carthandler == null)
     {
         carthandler = new CartHandler();
     }
     lblCartNumber.Text = carthandler.GetCount().ToString() == "0" ? "": carthandler.GetCount().ToString();
 }
Ejemplo n.º 11
0
 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();
     }
 }
Ejemplo n.º 12
0
        public ActionResult Confirm()
        {
            var cart = GetCart();

            OrderHandler.ConfirmOrder(ref cart);
            CartHandler.SaveCart(cart);

            return(View("Confirm"));
        }
Ejemplo n.º 13
0
 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();
     }
 }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
        public static Boolean checkstock(int productID)
        {
            Product product = CartHandler.getProductById(productID);

            if (product.productStock == 0)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 16
0
        public static Boolean isTypeExist(int TypeID)
        {
            PaymentType pt = CartHandler.getType(TypeID);

            if (pt == null)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 17
0
        public static Boolean isProductExist(int productID)
        {
            Product product = CartHandler.getProductById(productID);

            if (product == null)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 18
0
        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";
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        //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");
        }
Ejemplo n.º 21
0
 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);
     }
 }
Ejemplo n.º 22
0
        public static void removeCart(int productID)
        {
            List <Cart> cartlist2 = CartHandler.getCart();

            foreach (Cart cart in cartlist2)
            {
                if (cart.Quantity == 0)
                {
                    CartHandler.removeFromCart(productID);
                }
            }
        }
Ejemplo n.º 23
0
        private static bool checkSameProduct(int userId, int shoeId)
        {
            CartModel cart = CartHandler.getSpecificProductUserCart(userId, shoeId);

            if (cart != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 25
0
        void refresh()
        {
            List <Cart> cart = CartHandler.getCart();

            var dataSource = cart.Select(x => new
            {
                x.productID,
                x.Quantity
            });

            cartlist2.DataSource = dataSource;
            cartlist2.DataBind();
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
        public static bool deleteCartById(int cartId)
        {
            UserCart cart = CartHandler.findCartByID(cartId);

            if (cart != null)
            {
                CartRepository.deleteCart(cart);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 28
0
        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);
            }
        }
Ejemplo n.º 29
0
        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);
            }
        }
Ejemplo n.º 30
0
        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"));
        }