public int Edit(FormCollection form)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return -7;
                }
                else
                {
                    string orderIdString = form["orderId"];
                    string[] productIdString = Regex.Split(form["productId"], ",");
                    string[] priceString = Regex.Split(form["productPrice"], ",");
                    string[] quantityString = Regex.Split(form["productQuantity"], ",");
                    string depositAmountString = form["depositAmount"];
                    string deliveryDateString = form["deliveryDate"];
                    string orderNote = form["orderNote"];

                    List<CartViewModel> cartList = new List<CartViewModel>();
                    int totalQuantity = 0;
                    if (productIdString.Length == priceString.Length && priceString.Length == quantityString.Length)
                    {
                        for (int i = 0; i < productIdString.Length; i++)
                        {
                            CartViewModel cartViewModel = new CartViewModel();
                            cartViewModel.ProductId = Convert.ToInt32(productIdString[i]);
                            cartViewModel.RealPrice = Convert.ToInt32(priceString[i]);
                            int quantity = Convert.ToInt32(quantityString[i]);
                            cartViewModel.Quantity = quantity;
                            totalQuantity += quantity;
                            cartList.Add(cartViewModel);
                        }
                    }
                    if (totalQuantity == 0)
                    {
                        return -1;
                    }
                    OrderBusiness orderBusiness = new OrderBusiness(); ;
                    int minQuantity = orderBusiness.GetMinQuantity();
                    if (totalQuantity < minQuantity)
                    {
                        ViewBag.MinQuantity = minQuantity;
                        return -2;
                    }
                    int orderId = Convert.ToInt32(orderIdString);
                    int depositAmount = Convert.ToInt32(depositAmountString.Replace(".", ""));
                    DateTime deliveryDate = DateTime.ParseExact(deliveryDateString, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);

                    //Manh code them
                    Order order = db.Orders.SingleOrDefault(n => n.OrderId == orderId);
                    int cusUserId = order.CustomerUserId.Value;
                    Session["TempCusUserId"] = cusUserId;
                    MvcApplication.changeStatusNotifer.Dispose();
                    string dependencyCheckSql = string.Format("{0}{1}{2}", "SELECT OrderStatus FROM dbo.[Orders] WHERE CustomerUserId = ", cusUserId, " AND OrderStatus = 1");
                    MvcApplication.confirmToCustomerNotifer.Start("BMAChangeDB", dependencyCheckSql);
                    MvcApplication.confirmToCustomerNotifer.Change += this.OnChange6;
                    //het

                    int rs = orderBusiness.UpdateOrder(cartList, orderId, depositAmount, deliveryDate, staffUser.UserId, orderNote);
                    if (rs == 1)
                    {
                        Session["ProductList"] = null;
                    }

                    return rs;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public ActionResult UpdateMaterialList(FormCollection form)
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return null;
                }

                string[] productIdString = Regex.Split(form["productId"], ",");
                string[] priceString = Regex.Split(form["productPrice"], ",");
                string[] quantityString = Regex.Split(form["productQuantity"], ",");
                string orderIdString = form["orderId"];
                List<CartViewModel> cartList = new List<CartViewModel>();
                if (productIdString.Length == priceString.Length && priceString.Length == quantityString.Length)
                {
                    for (int i = 0; i < productIdString.Length; i++)
                    {
                        CartViewModel cartViewModel = new CartViewModel();
                        cartViewModel.ProductId = Convert.ToInt32(productIdString[i]);
                        cartViewModel.RealPrice = Convert.ToInt32(priceString[i]);
                        cartViewModel.Quantity = Convert.ToInt32(quantityString[i]);
                        cartList.Add(cartViewModel);
                    }
                }
                if (cartList.Count > 0)
                {
                    OrderBusiness orderBusiness = new OrderBusiness();
                    MaterialInfoForProductListViewModel material = orderBusiness.GetMaterialListForOrder(cartList);
                    material.OrderId = Convert.ToInt32(orderIdString);
                    return PartialView("MaterialListForOrder", material);
                }
                return PartialView("MaterialListForOrder", null);
            }
            catch (Exception)
            {
                return null;
            }
        }
        public int AddToCart(int[] productId, int[] productQuantity, int[] productPrice)
        {
            try
            {
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    return 0;
                }

                List<CartViewModel> cartList = new List<CartViewModel>();
                if (productId != null && productQuantity != null && productPrice != null && productId.Length > 0 &&
                    productQuantity.Length > 0 && productPrice.Length > 0 && productId.Length == productQuantity.Length && productQuantity.Length == productPrice.Length)
                {
                    for (int i = 0; i < productId.Length; i++)
                    {
                        OrderBusiness orderBusiness = new OrderBusiness();
                        Product product = orderBusiness.GetProductById(productId[i]);
                        if (productQuantity[i] > 0)
                        {
                            CartViewModel cartViewModel = new CartViewModel
                            {
                                ProductId = productId[i],
                                ProductName = product.ProductName,
                                Quantity = productQuantity[i],
                                RealPrice = productPrice[i],
                                StandardPrice = product.ProductStandardPrice
                            };
                            cartList.Add(cartViewModel);
                        }
                    }
                }
                if (cartList.Count > 0)
                {
                    Session["Cart"] = cartList;
                    return 1;
                }
                return 0;
            }
            catch (Exception)
            {
                return 0;
            }
        }