Learn how to generate an order with PetShop3.0 (5)

Source: Internet
Author: User

Click proceed to checkout to go to checkout. aspx, confirm and enter orderbilling. aspx. You can modify your information here. After you finish the modification, click "continue". A read-only page of personal information will appear. After confirmation, you will enter orderprocess. aspx: Here is the Order details and is read-only. Here, the order is added to the database and the shopping is complete.
Checkout. aspx extracts the data from the session and displays the data on the page.
Orderbilling. aspx: the information displayed at the beginning of this page can be written. In the onload event, processflow is used. accountcontroller. getaccountinfo obtains the creditcardinfo of the user and displays it in writable controls, such as the user control staticaddress. After you click OK, use storecreditcard to save the user information you just obtained to sessin.
Orderprocess. aspx is the final order generation page. The main method is:
Processflow. cartcontroller. purchasecart to see its implementation
Public orderinfo purchasecart (){

// Fetch the cart from session
Cart mycart = (Cart) httpcontext. Current. session [cart_key];

// Make some checks on the cart
If (myCart = null) | (myCart. Count = 0 )){

HttpContext. Current. Server. Transfer (URL_NOCART );
// HttpContext. Current. Response. Redirect (URL_NOCART, false );
Return null;

} Else {

// Build up the order
OrderInfo newOrder = new OrderInfo ();
NewOrder. UserId = (AccountInfo) HttpContext. Current. Session [ACCOUNT_KEY]). UserId;
NewOrder. CreditCard = (CreditCardInfo) HttpContext. Current. Session [CREDITCARD_KEY];
NewOrder. BillingAddress = (AddressInfo) HttpContext. Current. Session [BILLING_KEY];
NewOrder. ShippingAddress = (AddressInfo) HttpContext. Current. Session [SHIPPING_KEY];

NewOrder. LineItems = (LineItemInfo []) myCart. GetOrderLineItems (). ToArray (typeof (LineItemInfo ));

NewOrder. OrderTotal = myCart. Total;
NewOrder. Date = DateTime. Now;

// Send the order to the middle tier
OrderInsert order = new OrderInsert ();
// Insert data into the database
NewOrder. OrderId = order. Insert (newOrder );

// Clear the session objects used
HttpContext. Current. Session [CART_KEY] = null;
HttpContext. Current. Session [CREDITCARD_KEY] = null;
HttpContext. Current. Session [BILLING_KEY] = null;
HttpContext. Current. Session [SHIPPING_KEY] = null;

Return newOrder;
}
}

Order is mainly formed by the values stored in the Session, including the shopping cart.
There is a LineItemInfo in Order, which is composed of Cart. the GetOrderLineItems method returns the item part of the order based on the CartItemInfo value in cart. Compared with CartItemInfo, it mainly has a Line attribute, which is used to indicate the serial number of the item in the order.
The following describes the implementation of Insert.
Public int Insert (OrderInfo order ){

// Get an instance of the Order DAL using the DALFactory
IOrder dal = PetShop. DALFactory. Order. Create ();

// Call the insert method in the DAL to insert the header
Int orderId = dal. Insert (order );

// Get an instance of the Inventory business component
Inventory inventory = new Inventory ();
// Insert Inventory information into the database
Inventory. TakeStock (order. LineItems );

// As part of the sample application we have created a user
// You Can tested distributed transactions
// If the order has been created with the user 'Acid ',
// Then throw an exception which will rollback the entire transaction
If (order. userid = acid_user_id)
Throw new applicationexception (acid_error_msg );

// Set the orderid so that it can be returned to the caller
Return orderid;
}

Basically, there are so many things in the presentation layer that are basically all read here, hey

Author: Mike

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.