Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs @ 9582

Last change on this file since 9582 was 9582, checked in by fschoepp, 11 years ago

#1888:

  • Added an overview for users to inspect their orders
  • Order Administrators may now suspend or reactivate orders
  • When creating an order, its necessary to enter payment information (paypal, credit card,...) before
  • Also, the billing period and type must be entered during the creation of an order.
File size: 2.8 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using HeuristicLab.Services.Optimization.Billing.Interfaces;
4
5namespace HeuristicLab.Services.Optimization.Billing.Business {
6  public class MockupBillingService : IOptimizationBilling {
7
8    private static IList<Model.Product> products;
9    private static IDictionary<string, IList<Model.Order>> userToOrders;
10    private static IList<Model.Order> allOrders;
11    private static IDictionary<string, Model.User> users;
12    private static long maxId = 1;
13
14    static MockupBillingService() {
15      products = new List<Model.Product>();
16      products.Add(new Model.Product() {
17        Name = "Optimization-as-a-Service - Experiment execution",
18        Description = "Create and run your experiments within HeuristicLab Hive",
19        ProductId = 1,
20        Price = 10.0,
21        ProductType = "Optimization Service"
22      });
23      products.Add(new Model.Product() {
24        Name = "Whatever-o-matic - Experiment execution",
25        Description = "Another fine product",
26        ProductId = 2,
27        Price = 100.0,
28        ProductType = "Product"
29      });
30
31      userToOrders = new Dictionary<string, IList<Model.Order>>();
32      allOrders = new List<Model.Order>();
33      users = new Dictionary<string, Model.User>();
34    }
35
36    public IList<Model.Product> GetProducts() {
37      return products;
38    }
39
40    public void SaveOrder(Model.Order order) {
41      IList<Model.Order> orders;
42      if (!userToOrders.TryGetValue(order.User.Name, out orders)) {
43        userToOrders[order.User.Name] = orders = new List<Model.Order>();       
44      }
45      var oldOrder = (from o in orders where o.OrderId == order.OrderId select o).FirstOrDefault();
46      if (oldOrder == null) {
47        order.OrderId = maxId++;
48        orders.Add(order);
49        allOrders.Add(order);
50      }
51      else {
52        oldOrder.Invoices = order.Invoices;
53        oldOrder.OrderLines = order.OrderLines;
54        oldOrder.OrderStateId = order.OrderStateId;
55        oldOrder.State = order.State;
56        oldOrder.ActiveSince = order.ActiveSince;
57        oldOrder.ActiveUntil = order.ActiveUntil;
58        oldOrder.BillingPeriod = order.BillingPeriod;
59        oldOrder.BillingType = order.BillingType;
60      }
61    }
62
63    public IList<Model.Order> GetOrdersByState(Model.OrderState state) {
64      return (from o in allOrders where o.State == state select o).ToList();
65    }
66
67
68    public IList<Model.Order> GetOrders(string userName) {
69      return (from o in allOrders where o.User.Name == userName select o).ToList();
70    }
71
72
73    public Model.User GetUser(string userName) {
74      Model.User user;
75      if (!users.TryGetValue(userName, out user))
76        return null;
77      return user;
78    }
79
80    public void SaveUser(Model.User user) {
81      users[user.Name] = user;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.