Mercurial > pub > bltoolkit
comparison Demo/Asp.Net/BusinessLogic/OrderManager.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Transactions; | |
4 | |
5 using BLToolkit.Data; | |
6 | |
7 namespace PetShop.BusinessLogic | |
8 { | |
9 using DataAccess; | |
10 using ObjectModel; | |
11 | |
12 public class OrderManager | |
13 { | |
14 #region Order | |
15 | |
16 /// <summary> | |
17 /// Inserts the order and updates the inventory stock within a transaction. | |
18 /// </summary> | |
19 /// <param name="order">All information about the order</param> | |
20 public void InsertOrder(Order order) | |
21 { | |
22 using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) | |
23 { | |
24 OrderAccessor accessor = Accessor; | |
25 | |
26 using (DbManager db = accessor.GetDbManager()) | |
27 { | |
28 order.Courier = "UPS"; | |
29 order.Locale = "US_en"; | |
30 order.ID = accessor.Query.InsertAndGetIdentity(db, order); | |
31 | |
32 accessor.InsertStatus(db, order.ID); | |
33 | |
34 for (int i = 0; i < order.Lines.Length; i++) | |
35 { | |
36 OrderLineItem line = order.Lines[i]; | |
37 | |
38 line.OrderID = order.ID; | |
39 | |
40 accessor.Query.Insert(line); | |
41 } | |
42 } | |
43 | |
44 InventoryAccessor inv = InventoryAccessor.CreateInstance(); | |
45 | |
46 using (DbManager db = inv.GetDbManager()) | |
47 foreach (OrderLineItem line in order.Lines) | |
48 inv.TakeInventory(db, line.Quantity, line.ItemID); | |
49 | |
50 ts.Complete(); | |
51 } | |
52 } | |
53 | |
54 public List<Order> GetAllOrderList() | |
55 { | |
56 return Accessor.GetAllOrderList(); | |
57 } | |
58 | |
59 #endregion | |
60 | |
61 #region Accessor | |
62 | |
63 OrderAccessor Accessor | |
64 { | |
65 [System.Diagnostics.DebuggerStepThrough] | |
66 get { return OrderAccessor.CreateInstance(); } | |
67 } | |
68 | |
69 #endregion | |
70 } | |
71 } |