示例#1
0
        protected void createBtn_Click(object sender, EventArgs e)
        {
            int customerid = Convert.ToInt32(HttpContext.Current.Session["customerid"]);

            if (customerid != 0)
            {
                OrderModel db = new OrderModel();

                orders order = new orders();

                order.full_name       = FullName.Text;
                order.email           = email.Text;
                order.contact_num     = Convert.ToInt64(ContactNum.Text);
                order.current_address = address.Text;

                db.update_userinfo(customerid, order);
            }
            else
            {
                if (validation())
                {
                    OrderModel db         = new OrderModel();
                    string     userid     = Convert.ToString(HttpContext.Current.Session["userid"]);
                    orders     order      = new orders();
                    DateTime   date_added = DateTime.Now;
                    order.full_name             = FullName.Text;
                    order.email                 = email.Text;
                    order.contact_num           = Convert.ToInt64(ContactNum.Text);
                    order.current_address       = address.Text;
                    order.bank_code             = Convert.ToInt64(code.Text);
                    order.transection_date_time = datetime.Text;
                    order.total_price           = Convert.ToInt32(HttpContext.Current.Session["total_price"]);
                    order.User_ID               = userid;
                    order.Order_Date            = Convert.ToString(date_added);
                    order.status                = "Pending";
                    db.save_order(order);

                    int order_id = db.get_order(userid);

                    PurchaseModel   model     = new PurchaseModel();
                    List <Purchase> purchases = new List <Purchase>();
                    purchases = model.get_ordersinCart(userid);

                    foreach (Purchase purchase in purchases)
                    {
                        ordered_items items = new ordered_items();
                        items.product_id = purchase.ProductID;
                        items.quantity   = purchase.Quantity;
                        items.ordersID   = order_id;

                        db.save_order_items(items);
                    }

                    model.delete_purchase_by_userid(userid);
                    Response.Redirect("order_success.aspx");
                }
            }
        }