1 | using System.Collections.Generic;
|
---|
2 | using System.Linq;
|
---|
3 | using System.ServiceModel;
|
---|
4 | using HeuristicLab.Services.Optimization.Billing.DataAccess;
|
---|
5 | using HeuristicLab.Services.Optimization.Billing.Interfaces;
|
---|
6 | using HeuristicLab.Services.Optimization.Billing.Model;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Services.Optimization.Billing.Business {
|
---|
9 | [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
|
---|
10 | public class BillingService : IOptimizationBilling {
|
---|
11 | #region Properties
|
---|
12 |
|
---|
13 | private BillingDao billingDao;
|
---|
14 | private BillingDao BillingDao {
|
---|
15 | get {
|
---|
16 | if (billingDao == null) billingDao = new BillingDao();
|
---|
17 | return billingDao;
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | #endregion
|
---|
22 |
|
---|
23 | #region Product Methods
|
---|
24 |
|
---|
25 | public IList<Product> GetProducts() {
|
---|
26 | //TODO: Authentication
|
---|
27 | //TODO: Enable Transaction
|
---|
28 | return BillingDao.FindAllProducts().ToList();
|
---|
29 | }
|
---|
30 |
|
---|
31 | #endregion
|
---|
32 |
|
---|
33 | #region Order Methods
|
---|
34 |
|
---|
35 | public void SaveOrder(Order order) {
|
---|
36 | //TODO: Authentication
|
---|
37 | //TODO: Enable Transaction
|
---|
38 | BillingDao.AddOrder(order);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public IList<Order> GetOrdersByState(OrderState state) {
|
---|
42 | //TODO: Authentication
|
---|
43 | //TODO: Enable Transaction
|
---|
44 | return BillingDao.FindOrderBy(order => order.State == state).ToList();
|
---|
45 | }
|
---|
46 |
|
---|
47 | public IList<Order> GetOrders(string userName) {
|
---|
48 | //TODO: Authentication
|
---|
49 | //TODO: Enable Transaction
|
---|
50 | User user = GetUser(userName);
|
---|
51 | return BillingDao.FindOrderBy(order => order.User == user).ToList();
|
---|
52 | }
|
---|
53 |
|
---|
54 | #endregion
|
---|
55 |
|
---|
56 | #region User Methods
|
---|
57 |
|
---|
58 | public User GetUser(string userName) {
|
---|
59 | //TODO: Authentication
|
---|
60 | //TODO: Enable Transaction
|
---|
61 | return BillingDao.FindUserBy(u => u.Name == userName).First();
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void SaveUser(User user) {
|
---|
65 | //TODO: Authentication
|
---|
66 | //TODO: Enable Transaction
|
---|
67 | BillingDao.AddUser(user);
|
---|
68 | }
|
---|
69 |
|
---|
70 | #endregion
|
---|
71 |
|
---|
72 | #region UsageRecords Methods
|
---|
73 |
|
---|
74 | public IList<UsageRecord> GetUsageRecords(string userName) {
|
---|
75 | //TODO: Authentication
|
---|
76 | //TODO: Enable Transaction
|
---|
77 | User user = GetUser(userName);
|
---|
78 | return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList();
|
---|
79 | }
|
---|
80 |
|
---|
81 | #endregion
|
---|
82 |
|
---|
83 | #region Invoice Methods
|
---|
84 |
|
---|
85 | public IList<Invoice> GetInvoices(string userName) {
|
---|
86 | //TODO: Authentication
|
---|
87 | //TODO: Enable Transaction
|
---|
88 | User user = GetUser(userName);
|
---|
89 | return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList();
|
---|
90 | }
|
---|
91 |
|
---|
92 | #endregion
|
---|
93 | }
|
---|
94 | }
|
---|