Example #1
0
        public ActionResult AddProduct(string orderId, string productId, int quantity = 0, double discount = 0)
        {
            if (string.IsNullOrEmpty(orderId))
            {
                return(RedirectToAction("Index"));
            }
            if (string.IsNullOrEmpty(productId) || quantity < 0)
            {
                return(Redirect("~/Order/OrderDetails/" + orderId));
            }
            if (quantity < 1 || discount < 0 || discount > 100)
            {
                return(Redirect("~/Order/OrderDetails/" + orderId));
            }
            else
            {
                double unitprice = CatalogBLL.Product_Get(productId).UnitPrice;

                OrderDetails orderDetails = new OrderDetails();
                orderDetails.OrderID   = Convert.ToInt32(orderId);
                orderDetails.ProductID = Convert.ToInt32(productId);
                orderDetails.Quantity  = quantity;
                orderDetails.Discount  = discount;
                orderDetails.UnitPrice = unitprice;
                bool   check = OrderBLL.CheckOrder(orderId, productId);
                string rs    = "";
                if (check)
                {
                    rs = OrderBLL.Order_Update_Product(orderDetails, "add");
                }
                else
                {
                    rs = OrderBLL.Order_Add_Product(orderDetails);
                }
                return(Redirect("~/Order/OrderDetails/" + rs));
            }
        }