1: public partial class PlaceOrder : Page {
2: private IDaoFactory daoFactory = new NHibernateDaoFactory();
3: private BurrowFramework bf = new BurrowFramework();
4:
5: /// <summary>
6: /// Store the placing order in the Conversation.Items so that it has the same life span as the Conversation
7: /// </summary>
8: public Order placingOrder {
9: get { return (Order) bf.CurrentConversation.Items["placingOrder"]; }
10: set { bf.CurrentConversation.Items["placingOrder"] = value; }
11: }
12:
13: protected void Page_Load(object sender, EventArgs e) {
14: if (!IsPostBack) {
15: ddlCustomers.DataSource = daoFactory.GetCustomerDao().GetAll();
16: ddlCustomers.DataBind();
17: }
18: }
19:
20: protected void Step1(object sender, EventArgs e) {
21: //start an atomic Conversation that span over postbacks
22: bf.CurrentConversation.SpanWithPostBacks(TransactionStrategy.BusinessTransaction);
23: Customer selectedCustomer = daoFactory.GetCustomerDao().GetById(ddlCustomers.SelectedValue, false);
24: placingOrder = new Order(selectedCustomer) ;
25: phSelectCustomer.Visible = false;
26: phEnterShipToName.Visible = true;
27: }
28:
29: protected void btnStep2(object sender, EventArgs e) {
30: placingOrder.ShipToName = tbShipToName.Text;
31: phEnterShipToName.Visible = false;
32: phConfirm.Visible = true;
33: lCustomer.Text = placingOrder.OrderedBy.ToString();
34: lShipTo.Text = placingOrder.ShipToName;
35: }
36:
37: protected void Cancel(object sender, EventArgs e) {
38: bf.CurrentConversation.GiveUp(); // give up the current spanning conversation
39: phEnterShipToName.Visible = false;
40: StartOver();
41: }
42:
43: private void StartOver() {
44: phSelectCustomer.Visible = true;
45: }
46:
47: protected void Finish(object sender, EventArgs e) {
48: placingOrder.OrderDate = DateTime.Now;
49: daoFactory.GetOrderDao().Save(placingOrder);
50: bf.CurrentConversation.FinishSpan(); //finish up the current spanning conversation
51: placingOrder = null; //reset the placing order to null after conversation is done is a good practice
52: phConfirm.Visible = false;
53: StartOver();
54: }
55: }