public ActionResult Checkout(FormCollection f)
        {
            User_Account  userAccount = (User_Account)Session["USER"];
            DateTime      today       = DateTime.Today;
            string        email       = userAccount.Email;
            string        name        = f["txtName"];
            string        address     = f["txtAddress"];
            string        province    = f["province"];
            string        district    = f["district"];
            string        town        = f["town"];
            string        orderPhone  = f["txtNumber"];
            Order_Details order       = new Order_Details
            {
                Email           = email,
                Ordered_Date    = today,
                Delivered       = false,
                Cancelled_Order = false,
                Reason_Cancel   = "",
                Order_Name      = name,
                Exact_Address   = address,
                Order_Phone     = orderPhone,
                Province_ID     = Int32.Parse(province),
                District_ID     = Int32.Parse(district),
                Town_ID         = Int32.Parse(town)
            };
            OrderDetailsDAL dal            = new OrderDetailsDAL();
            int             orderDetailsId = dal.addOrder(order);

            if (orderDetailsId >= 0)
            {
                ICollection <Product_Cart> productCarts   = userAccount.Product_Cart;
                Product_CartDAL            productCartDal = new Product_CartDAL();
                foreach (var item in productCarts)
                {
                    ProductOrderDetailsDAL podDal = new ProductOrderDetailsDAL();
                    Product_Order_Details  pod    = new Product_Order_Details()
                    {
                        Product_ID       = item.Product_ID,
                        Order_ID         = orderDetailsId,
                        Order_Quantity   = (int)item.Quantity,
                        Price            = item.Product.Price,
                        Discount_Percent = item.Product.DiscountPercent,
                    };

                    podDal.addProductOrderDetails(pod);

                    productCartDal.deleteRecord(item.Product_ID, userAccount.Email);
                }
                productCarts.Clear();
                Session.Remove("CART");
                return(RedirectToAction("Index", "Congratulate"));
            }

            return(View());
        }
Пример #2
0
        public bool addProductOrderDetails(Product_Order_Details pod)
        {
            string sql = "INSERT Product_Order_Details "
                         + "VALUES(@productId, @orderId, @orderQuantity, @price, @discountPercent, '')";
            SqlParameter productIdParam = new SqlParameter("@productId", pod.Product_ID);
            SqlParameter orderIdParam   = new SqlParameter("@orderId", pod.Order_ID);
            SqlParameter quantityParam  = new SqlParameter("@orderQuantity", pod.Order_Quantity);
            SqlParameter priceParam     = new SqlParameter("@price", pod.Price);
            SqlParameter discountParam  = new SqlParameter("@discountPercent", pod.Discount_Percent);

            return(DataProvider.ExecuteNonQuery(sql, CommandType.Text, productIdParam, orderIdParam, quantityParam, priceParam, discountParam));
        }