[9577] | 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 |
|
---|
[10013] | 21 | private ITransactionManager transaction;
|
---|
| 22 | private ITransactionManager Transaction {
|
---|
| 23 | get {
|
---|
| 24 | if (transaction == null) transaction = new TransactionManager();
|
---|
| 25 | return transaction;
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[9577] | 29 | #endregion
|
---|
| 30 |
|
---|
| 31 | #region Product Methods
|
---|
| 32 |
|
---|
| 33 | public IList<Product> GetProducts() {
|
---|
| 34 | //TODO: Authentication
|
---|
[10013] | 35 | return Transaction.UseTransaction(() => {
|
---|
| 36 | return BillingDao.FindAllProducts().ToList();
|
---|
| 37 | });
|
---|
[9577] | 38 | }
|
---|
| 39 |
|
---|
[9619] | 40 | public IList<Product> GetProductByName(string productName) {
|
---|
| 41 | //TODO: Authentication
|
---|
[10013] | 42 | return Transaction.UseTransaction(() => {
|
---|
| 43 | return BillingDao.FindProdcutBy(prod => prod.Name == productName).ToList();
|
---|
| 44 | });
|
---|
[9619] | 45 | }
|
---|
| 46 |
|
---|
[9577] | 47 | #endregion
|
---|
| 48 |
|
---|
| 49 | #region Order Methods
|
---|
| 50 |
|
---|
| 51 | public void SaveOrder(Order order) {
|
---|
| 52 | //TODO: Authentication
|
---|
[10013] | 53 | Transaction.UseTransaction(() => {
|
---|
| 54 | BillingDao.InsertOrUpdateOrder(order);
|
---|
| 55 | });
|
---|
[9577] | 56 | }
|
---|
| 57 |
|
---|
| 58 | public IList<Order> GetOrdersByState(OrderState state) {
|
---|
| 59 | //TODO: Authentication
|
---|
[10013] | 60 | return Transaction.UseTransaction(() => {
|
---|
| 61 | return BillingDao.FindOrderBy(order => order.StateValue == (int)state).ToList();
|
---|
| 62 | });
|
---|
[9577] | 63 | }
|
---|
| 64 |
|
---|
[9582] | 65 | public IList<Order> GetOrders(string userName) {
|
---|
[9602] | 66 | //TODO: Authentication
|
---|
[10013] | 67 | return Transaction.UseTransaction(() => {
|
---|
| 68 | User user = GetUser(userName);
|
---|
| 69 | return BillingDao.FindOrderBy(order => order.User == user).ToList();
|
---|
| 70 | });
|
---|
[9582] | 71 | }
|
---|
| 72 |
|
---|
[9619] | 73 | public void UpdateOrder(Order order) {
|
---|
[9645] | 74 | //TODO: Authentication
|
---|
[10013] | 75 | Transaction.UseTransaction(() => {
|
---|
| 76 | BillingDao.InsertOrUpdateOrder(order);
|
---|
| 77 | });
|
---|
[9619] | 78 | }
|
---|
| 79 |
|
---|
[9602] | 80 | #endregion
|
---|
[9582] | 81 |
|
---|
[9602] | 82 | #region User Methods
|
---|
| 83 |
|
---|
[9582] | 84 | public User GetUser(string userName) {
|
---|
[9602] | 85 | //TODO: Authentication
|
---|
[10013] | 86 | return Transaction.UseTransaction(() => {
|
---|
| 87 | return BillingDao.FindUserBy(u => u.Name == userName).First();
|
---|
| 88 | });
|
---|
[9582] | 89 | }
|
---|
| 90 |
|
---|
| 91 | public void SaveUser(User user) {
|
---|
[9602] | 92 | //TODO: Authentication
|
---|
[10013] | 93 | Transaction.UseTransaction(() => {
|
---|
| 94 | BillingDao.InsertOrUpdateUser(user);
|
---|
| 95 | });
|
---|
[9582] | 96 | }
|
---|
[9586] | 97 |
|
---|
[9602] | 98 | #endregion
|
---|
[9586] | 99 |
|
---|
[9602] | 100 | #region UsageRecords Methods
|
---|
| 101 |
|
---|
[9586] | 102 | public IList<UsageRecord> GetUsageRecords(string userName) {
|
---|
[9602] | 103 | //TODO: Authentication
|
---|
[10013] | 104 | return Transaction.UseTransaction(() => {
|
---|
| 105 | User user = GetUser(userName);
|
---|
| 106 | return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList();
|
---|
| 107 | });
|
---|
[9586] | 108 | }
|
---|
| 109 |
|
---|
[9619] | 110 | public IList<UsageRecord> GetUsageRecords(string username, System.DateTime from, System.DateTime to) {
|
---|
| 111 | throw new System.NotImplementedException();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[9602] | 114 | #endregion
|
---|
[9586] | 115 |
|
---|
[9602] | 116 | #region Invoice Methods
|
---|
| 117 |
|
---|
[9586] | 118 | public IList<Invoice> GetInvoices(string userName) {
|
---|
[9602] | 119 | //TODO: Authentication
|
---|
[10013] | 120 | return Transaction.UseTransaction(() => {
|
---|
| 121 | User user = GetUser(userName);
|
---|
| 122 | return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList();
|
---|
| 123 | });
|
---|
[9586] | 124 | }
|
---|
[9602] | 125 |
|
---|
[9645] | 126 | public void SaveInvoice(Invoice invoice) {
|
---|
| 127 | //TODO: Authentication
|
---|
[10013] | 128 | Transaction.UseTransaction(() => {
|
---|
| 129 | BillingDao.InsertOrUpdateInvoice(invoice);
|
---|
| 130 | });
|
---|
[9645] | 131 | }
|
---|
| 132 |
|
---|
[9602] | 133 | #endregion
|
---|
[9577] | 134 | }
|
---|
| 135 | }
|
---|