Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs @ 10594

Last change on this file since 10594 was 10013, checked in by spimming, 11 years ago

#1888:

  • enabled transactions
  • enabled tracing output
  • set correct invoice data
  • saving invoices
File size: 3.7 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using System.ServiceModel;
4using HeuristicLab.Services.Optimization.Billing.DataAccess;
5using HeuristicLab.Services.Optimization.Billing.Interfaces;
6using HeuristicLab.Services.Optimization.Billing.Model;
7
8namespace 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    private ITransactionManager transaction;
22    private ITransactionManager Transaction {
23      get {
24        if (transaction == null) transaction = new TransactionManager();
25        return transaction;
26      }
27    }
28
29    #endregion
30
31    #region Product Methods
32
33    public IList<Product> GetProducts() {
34      //TODO: Authentication
35      return Transaction.UseTransaction(() => {
36        return BillingDao.FindAllProducts().ToList();
37      });
38    }
39
40    public IList<Product> GetProductByName(string productName) {
41      //TODO: Authentication
42      return Transaction.UseTransaction(() => {
43        return BillingDao.FindProdcutBy(prod => prod.Name == productName).ToList();
44      });
45    }
46
47    #endregion
48
49    #region Order Methods
50
51    public void SaveOrder(Order order) {
52      //TODO: Authentication
53      Transaction.UseTransaction(() => {
54        BillingDao.InsertOrUpdateOrder(order);
55      });
56    }
57
58    public IList<Order> GetOrdersByState(OrderState state) {
59      //TODO: Authentication
60      return Transaction.UseTransaction(() => {
61        return BillingDao.FindOrderBy(order => order.StateValue == (int)state).ToList();
62      });
63    }
64
65    public IList<Order> GetOrders(string userName) {
66      //TODO: Authentication
67      return Transaction.UseTransaction(() => {
68        User user = GetUser(userName);
69        return BillingDao.FindOrderBy(order => order.User == user).ToList();
70      });
71    }
72
73    public void UpdateOrder(Order order) {
74      //TODO: Authentication
75      Transaction.UseTransaction(() => {
76        BillingDao.InsertOrUpdateOrder(order);
77      });
78    }
79
80    #endregion
81
82    #region User Methods
83
84    public User GetUser(string userName) {
85      //TODO: Authentication
86      return Transaction.UseTransaction(() => {
87        return BillingDao.FindUserBy(u => u.Name == userName).First();
88      });
89    }
90
91    public void SaveUser(User user) {
92      //TODO: Authentication
93      Transaction.UseTransaction(() => {
94        BillingDao.InsertOrUpdateUser(user);
95      });
96    }
97
98    #endregion
99
100    #region UsageRecords Methods
101
102    public IList<UsageRecord> GetUsageRecords(string userName) {
103      //TODO: Authentication
104      return Transaction.UseTransaction(() => {
105        User user = GetUser(userName);
106        return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList();
107      });
108    }
109
110    public IList<UsageRecord> GetUsageRecords(string username, System.DateTime from, System.DateTime to) {
111      throw new System.NotImplementedException();
112    }
113
114    #endregion
115
116    #region Invoice Methods
117
118    public IList<Invoice> GetInvoices(string userName) {
119      //TODO: Authentication
120      return Transaction.UseTransaction(() => {
121        User user = GetUser(userName);
122        return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList();
123      });
124    }
125
126    public void SaveInvoice(Invoice invoice) {
127      //TODO: Authentication
128      Transaction.UseTransaction(() => {
129        BillingDao.InsertOrUpdateInvoice(invoice);
130      });
131    }
132
133    #endregion
134  }
135}
Note: See TracBrowser for help on using the repository browser.