Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9844 was 9645, checked in by spimming, 12 years ago

#1888:

  • Model classes implement new interface to track current state of entity
  • Mark EntityState property as 'not mapped'
  • Set hook to initialize entity as unchanged
  • Extension method for DbContext to apply changes only on modified entity
File size: 3.2 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    #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    public IList<Product> GetProductByName(string productName) {
32      //TODO: Authentication
33      //TODO: Enable Transaction
34      return BillingDao.FindProdcutBy(prod => prod.Name == productName).ToList();
35    }
36
37    #endregion
38
39    #region Order Methods
40
41    public void SaveOrder(Order order) {
42      //TODO: Authentication
43      //TODO: Enable Transaction
44      BillingDao.InsertOrUpdateOrder(order);
45    }
46
47    public IList<Order> GetOrdersByState(OrderState state) {
48      //TODO: Authentication
49      //TODO: Enable Transaction
50      return BillingDao.FindOrderBy(order => order.StateValue == (int)state).ToList();
51    }
52
53    public IList<Order> GetOrders(string userName) {
54      //TODO: Authentication
55      //TODO: Enable Transaction
56      User user = GetUser(userName);
57      return BillingDao.FindOrderBy(order => order.User == user).ToList();
58    }
59
60    public void UpdateOrder(Order order) {
61      //TODO: Authentication
62      //TODO: Enable Transaction
63      BillingDao.InsertOrUpdateOrder(order);
64    }
65
66    #endregion
67
68    #region User Methods
69
70    public User GetUser(string userName) {
71      //TODO: Authentication
72      //TODO: Enable Transaction
73      return BillingDao.FindUserBy(u => u.Name == userName).First();
74    }
75
76    public void SaveUser(User user) {
77      //TODO: Authentication
78      //TODO: Enable Transaction
79      BillingDao.InsertOrUpdateUser(user);
80    }
81
82    #endregion
83
84    #region UsageRecords Methods
85
86    public IList<UsageRecord> GetUsageRecords(string userName) {
87      //TODO: Authentication
88      //TODO: Enable Transaction
89      User user = GetUser(userName);
90      return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList();
91    }
92
93    public IList<UsageRecord> GetUsageRecords(string username, System.DateTime from, System.DateTime to) {
94      throw new System.NotImplementedException();
95    }
96
97    #endregion
98
99    #region Invoice Methods
100
101    public IList<Invoice> GetInvoices(string userName) {
102      //TODO: Authentication
103      //TODO: Enable Transaction
104      User user = GetUser(userName);
105      return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList();
106    }
107
108    public void SaveInvoice(Invoice invoice) {
109      //TODO: Authentication
110      //TODO: Enable Transaction
111      BillingDao.InsertOrUpdateInvoice(invoice);
112    }
113
114    #endregion
115  }
116}
Note: See TracBrowser for help on using the repository browser.