Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/App.config
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/App.config	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/App.config	(revision 9577)
@@ -0,0 +1,21 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <connectionStrings>
+    <add name="BillingContext" connectionString="ADJUST_ME" providerName="System.Data.SqlClient"/>
+  </connectionStrings>
+  <configSections>
+    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+  </configSections>
+  <entityFramework>
+    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
+  </entityFramework>
+  <system.serviceModel>
+    <services>
+      <service name="HeuristicLab.Services.Optimization.Billing">
+        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="MexEndpoint" contract="IMetadataExchange" />
+        <endpoint binding="wsHttpBinding" name="WSHttpBinding_IOptimizationBilling" contract="HeuristicLab.Services.Optimization.Billing.Interfaces.IOptimizationBilling" />
+      </service>
+    </services>
+  </system.serviceModel>
+</configuration>
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs	(revision 9577)
@@ -0,0 +1,49 @@
+﻿using System.Collections.Generic;
+using System.Linq;
+using System.ServiceModel;
+using HeuristicLab.Services.Optimization.Billing.DataAccess;
+using HeuristicLab.Services.Optimization.Billing.Interfaces;
+using HeuristicLab.Services.Optimization.Billing.Model;
+
+namespace HeuristicLab.Services.Optimization.Billing.Business {
+  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
+  public class BillingService : IOptimizationBilling {
+    #region Properties
+
+    private BillingDao billingDao;
+    private BillingDao BillingDao {
+      get {
+        if (billingDao == null) billingDao = new BillingDao();
+        return billingDao;
+      }
+    }
+
+    #endregion
+
+    #region Product Methods
+
+    public IList<Product> GetProducts() {
+      //TODO: Authentication
+      //TODO: Enable Transaction
+      return BillingDao.FindAllProducts().ToList();
+    }
+
+    #endregion
+
+    #region Order Methods
+
+    public void SaveOrder(Order order) {
+      //TODO: Authentication
+      //TODO: Enable Transaction
+      BillingDao.AddOrder(order);
+    }
+
+    public IList<Order> GetOrdersByState(OrderState state) {
+      //TODO: Authentication
+      //TODO: Enable Transaction
+      return BillingDao.FindOrderBy(order => order.State == state).ToList();
+    }
+
+    #endregion
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingServiceProvider.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingServiceProvider.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingServiceProvider.cs	(revision 9577)
@@ -0,0 +1,11 @@
+﻿
+using HeuristicLab.Services.Optimization.Billing.Interfaces;
+namespace HeuristicLab.Services.Optimization.Billing.Business {
+  public static class BillingServiceProvider {
+    private static IOptimizationBilling instance = new BillingService();
+
+    public static IOptimizationBilling Instance {
+      get { return instance; }
+    }
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs	(revision 9577)
@@ -0,0 +1,50 @@
+﻿using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Services.Optimization.Billing.Interfaces;
+
+namespace HeuristicLab.Services.Optimization.Billing.Business {
+  public class MockupBillingService : IOptimizationBilling {
+
+    private static IList<Model.Product> products;
+    private static IDictionary<string, IList<Model.Order>> userToOrders;
+    private static IList<Model.Order> allOrders;
+
+    static MockupBillingService() {
+      products = new List<Model.Product>();
+      products.Add(new Model.Product() {
+        Name = "Optimization-as-a-Service - Experiment execution",
+        Description = "Create and run your experiments within HeuristicLab Hive",
+        ProductId = 1,
+        Price = 10.0,
+        ProductType = "Optimization Service"
+      });
+      products.Add(new Model.Product() {
+        Name = "Whatever-o-matic - Experiment execution",
+        Description = "Another fine product",
+        ProductId = 2,
+        Price = 100.0,
+        ProductType = "Product"
+      });
+
+      userToOrders = new Dictionary<string, IList<Model.Order>>();
+      allOrders = new List<Model.Order>();
+    }
+
+    public IList<Model.Product> GetProducts() {
+      return products;
+    }
+
+    public void SaveOrder(Model.Order order) {
+      IList<Model.Order> orders;
+      if (!userToOrders.TryGetValue(order.User.Name, out orders)) {
+        userToOrders[order.User.Name] = orders = new List<Model.Order>();
+      }
+      orders.Add(order);
+      allOrders.Add(order);
+    }
+
+    public IList<Model.Order> GetOrdersByState(Model.OrderState state) {
+      return (from o in allOrders where o.State == state select o).ToList();
+    }
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs	(revision 9577)
@@ -0,0 +1,104 @@
+﻿using System.Data.Entity;
+using System.Data.Entity.ModelConfiguration;
+using System.Data.Entity.ModelConfiguration.Conventions;
+using HeuristicLab.Services.Optimization.Billing.Model;
+
+namespace HeuristicLab.Services.Optimization.Billing.DataAccess {
+  public class BillingContext : DbContext {
+    public DbSet<ContactInformation> ContactInformations { get; set; }
+    public DbSet<Product> Products { get; set; }
+    public DbSet<User> Users { get; set; }
+    public DbSet<Order> Orders { get; set; }
+    public DbSet<OrderLine> OrderLines { get; set; }
+    public DbSet<Invoice> Invoices { get; set; }
+    public DbSet<InvoiceLine> InvoiceLines { get; set; }
+
+    // enum PaymentMethod
+    // enum OrderState 
+
+    public BillingContext()
+      : base("name=BillingContext") {
+
+    }
+
+    public BillingContext(string connectionString)
+      : base(connectionString) {
+
+    }
+
+    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
+      modelBuilder.Configurations.Add(new OrderConfiguration());
+      modelBuilder.Configurations.Add(new OrderLineConfiguration());
+      modelBuilder.Configurations.Add(new InvoiceConfiguration());
+      modelBuilder.Configurations.Add(new InvoiceLineConfiguration());
+      modelBuilder.Configurations.Add(new UsageRecordConfiguration());
+      modelBuilder.Configurations.Add(new UsageRecordLineConfiguration());
+
+      modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
+
+      base.OnModelCreating(modelBuilder);
+    }
+
+    #region EntityTypeConfigurations
+
+    private class OrderConfiguration : EntityTypeConfiguration<Order> {
+      internal OrderConfiguration() {
+        this.HasRequired(o => o.User).WithMany().HasForeignKey(o => o.UserId);
+        //this.HasMany<Invoice>(o => o.Invoices).WithRequired().HasForeignKey(i => i.OrderId);
+        // TODO: OrderState?
+      }
+    }
+
+    private class OrderLineConfiguration : EntityTypeConfiguration<OrderLine> {
+      internal OrderLineConfiguration() {
+        this.HasRequired(ol => ol.Order).WithMany().HasForeignKey(ol => ol.OrderId);
+        this.HasRequired(ol => ol.Product).WithMany().HasForeignKey(ol => ol.ProductId);
+      }
+    }
+
+    private class InvoiceConfiguration : EntityTypeConfiguration<Invoice> {
+      internal InvoiceConfiguration() {
+        this.HasRequired(i => i.User).WithMany().HasForeignKey(i => i.UserId);
+        this.HasRequired(i => i.Order).WithMany().HasForeignKey(i => i.OrderId);
+      }
+    }
+
+    private class InvoiceLineConfiguration : EntityTypeConfiguration<InvoiceLine> {
+      internal InvoiceLineConfiguration() {
+        this.HasRequired(il => il.Invoice).WithMany().HasForeignKey(il => il.InvoiceId);
+        this.HasRequired(il => il.Product).WithMany().HasForeignKey(il => il.ProductId);
+      }
+    }
+
+    private class UsageRecordConfiguration : EntityTypeConfiguration<UsageRecord> {
+      internal UsageRecordConfiguration() {
+        this.HasRequired(ur => ur.User).WithMany().HasForeignKey(ur => ur.UserId);
+      }
+    }
+
+    private class UsageRecordLineConfiguration : EntityTypeConfiguration<UsageRecordLine> {
+      internal UsageRecordLineConfiguration() {
+        this.HasRequired(url => url.UsageRecord).WithMany().HasForeignKey(url => url.UsageRecordId);
+      }
+    }
+
+    #endregion
+
+    #region DB Seed Methods
+
+    public class BillingContextInitiliazer : DropCreateDatabaseIfModelChanges<BillingContext> {
+      protected override void Seed(BillingContext context) {
+        context.Products.Add(new Model.Product() {
+          Name = "Optimization-as-a-Service - Experiment execution",
+          Description = "Create and run your experiments within HeuristicLab Hive",
+          ProductId = 1,
+          Price = 10.0,
+          ProductType = "Optimization Service"
+        });
+        context.SaveChanges();
+      }
+    }
+
+    #endregion
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs	(revision 9577)
@@ -0,0 +1,114 @@
+﻿
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using HeuristicLab.Services.Optimization.Billing.Model;
+namespace HeuristicLab.Services.Optimization.Billing.DataAccess {
+  public class BillingDao {
+
+    #region Context Creation and Execution
+
+    private BillingContext CreateContext() {
+      BillingContext context = new BillingContext("name=BillingContext");
+      return context;
+    }
+
+    private delegate T ExecuteWithContextDelegate<T>(BillingContext context);
+    private delegate void ExecuteWithContextDelegate(BillingContext context);
+
+    private void ExecuteWithContext(ExecuteWithContextDelegate call) {
+      BillingContext context = null;
+      try {
+        using (context = CreateContext()) {
+          call(context);
+        }
+      }
+      finally {
+        if (context.Database.Connection.State == System.Data.ConnectionState.Open) {
+          context.Database.Connection.Close();
+        }
+      }
+    }
+
+    private T ExecuteWithContext<T>(ExecuteWithContextDelegate<T> call) {
+      BillingContext context = null;
+      try {
+        using (context = CreateContext()) {
+          T result = call(context);
+          return result;
+        }
+      }
+      finally {
+        if (context.Database.Connection.State == System.Data.ConnectionState.Open) {
+          context.Database.Connection.Close();
+        }
+      }
+    }
+
+    #endregion
+
+    #region Product Methods
+
+    public Product FindProductById(long id) {
+      return ExecuteWithContext<Product>((context) => {
+        return context.Products.FirstOrDefault(prod => prod.ProductId == id);
+      });
+    }
+
+    public IEnumerable<Product> FindProdcutBy(Expression<Func<Product, bool>> predicate) {
+      using (var context = CreateContext()) {
+        var products = context.Products.Where(predicate).ToList();
+        return products;
+      }
+    }
+
+    public IEnumerable<Product> FindAllProducts() {
+      using (var context = CreateContext()) {
+        var products = context.Products.ToList();
+        return products;
+      }
+    }
+
+    public void AddProduct(Product entity) {
+      ExecuteWithContext((context) => {
+        context.Products.Add(entity);
+        context.SaveChanges();
+      });
+    }
+
+    public void UpdateProduct(Product entity) {
+      ExecuteWithContext((context) => {
+        context.Products.Attach(entity);
+        context.Entry(entity).State = System.Data.EntityState.Modified;
+        context.SaveChanges();
+      });
+    }
+
+    void DeleteProduct(Product entity) {
+      ExecuteWithContext((context) => {
+        context.Products.Remove(entity);
+      });
+    }
+
+    #endregion
+
+    #region Order Methods
+
+    public void AddOrder(Order order) {
+      ExecuteWithContext((context) => {
+        context.Orders.Add(order);
+        context.SaveChanges();
+      });
+    }
+
+    public IEnumerable<Order> FindOrderBy(Expression<Func<Order, bool>> predicate) {
+      using (var context = CreateContext()) {
+        var orders = context.Orders.Where(predicate).ToList();
+        return orders;
+      }
+    }
+
+    #endregion
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IEntity.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IEntity.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IEntity.cs	(revision 9577)
@@ -0,0 +1,7 @@
+﻿
+namespace HeuristicLab.Services.Optimization.Billing.Interfaces {
+  public interface IEntity<ID> {
+    ID Id { get; set; }
+    bool IsDeleted { get; set; }
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IGenericDao.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IGenericDao.cs	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IGenericDao.cs	(revision 9577)
@@ -0,0 +1,16 @@
+﻿using System;
+using System.Linq;
+using System.Linq.Expressions;
+
+namespace HeuristicLab.Services.Optimization.Billing.DAL {
+
+  public interface IGenericDao<T, ID> {
+    T FindById(ID id);
+    IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
+    IQueryable<T> FindAll();
+    void Add(T entity);
+    void Update(T entity);
+    void Delete(T entity);
+    void Commit();
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/packages.config
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/packages.config	(revision 9577)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/packages.config	(revision 9577)
@@ -0,0 +1,4 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
+</packages>
