[9577] | 1 |
|
---|
| 2 | using System;
|
---|
| 3 | using System.Collections.Generic;
|
---|
[9645] | 4 | using System.Data;
|
---|
[9619] | 5 | using System.Data.Entity;
|
---|
[9577] | 6 | using System.Linq;
|
---|
| 7 | using System.Linq.Expressions;
|
---|
| 8 | using HeuristicLab.Services.Optimization.Billing.Model;
|
---|
[9645] | 9 | using HeuristicLab.Services.Optimization.Billing.Utils;
|
---|
[9577] | 10 | namespace HeuristicLab.Services.Optimization.Billing.DataAccess {
|
---|
| 11 | public class BillingDao {
|
---|
| 12 |
|
---|
| 13 | #region Context Creation and Execution
|
---|
| 14 |
|
---|
| 15 | private BillingContext CreateContext() {
|
---|
| 16 | BillingContext context = new BillingContext("name=BillingContext");
|
---|
| 17 | return context;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | #region Product Methods
|
---|
| 23 |
|
---|
| 24 | public Product FindProductById(long id) {
|
---|
[9645] | 25 | using (var context = CreateContext()) {
|
---|
[9577] | 26 | return context.Products.FirstOrDefault(prod => prod.ProductId == id);
|
---|
[9645] | 27 | }
|
---|
[9577] | 28 | }
|
---|
| 29 |
|
---|
| 30 | public IEnumerable<Product> FindProdcutBy(Expression<Func<Product, bool>> predicate) {
|
---|
| 31 | using (var context = CreateContext()) {
|
---|
| 32 | var products = context.Products.Where(predicate).ToList();
|
---|
| 33 | return products;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public IEnumerable<Product> FindAllProducts() {
|
---|
| 38 | using (var context = CreateContext()) {
|
---|
| 39 | var products = context.Products.ToList();
|
---|
| 40 | return products;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[9645] | 44 | public void InsertOrUpdateProduct(Product entity) {
|
---|
| 45 | using (var context = CreateContext()) {
|
---|
| 46 | throw new NotImplementedException();
|
---|
| 47 | }
|
---|
[9577] | 48 | }
|
---|
| 49 |
|
---|
| 50 | void DeleteProduct(Product entity) {
|
---|
[9645] | 51 | using (var context = CreateContext()) {
|
---|
| 52 | throw new NotImplementedException();
|
---|
| 53 | }
|
---|
[9577] | 54 | }
|
---|
| 55 |
|
---|
| 56 | #endregion
|
---|
| 57 |
|
---|
| 58 | #region Order Methods
|
---|
| 59 |
|
---|
[9645] | 60 | public void InsertOrUpdateOrder(Order entity) {
|
---|
| 61 | using (var context = CreateContext()) {
|
---|
| 62 | context.Orders.Add(entity);
|
---|
| 63 | context.ApplyStateChanges();
|
---|
[9577] | 64 | context.SaveChanges();
|
---|
[9645] | 65 | }
|
---|
[9577] | 66 | }
|
---|
| 67 |
|
---|
| 68 | public IEnumerable<Order> FindOrderBy(Expression<Func<Order, bool>> predicate) {
|
---|
| 69 | using (var context = CreateContext()) {
|
---|
[9619] | 70 | var orders = context.Orders
|
---|
| 71 | .Include(o => o.OrderLines)
|
---|
| 72 | .Include(o => o.User)
|
---|
[9641] | 73 | .Include(o => o.User.ContactInformation)
|
---|
[9619] | 74 | .Include(o => o.Invoices)
|
---|
| 75 | .Include(o => o.OrderLines.Select(ol => ol.Product))
|
---|
| 76 | .Where(predicate).ToList();
|
---|
[9577] | 77 | return orders;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | #endregion
|
---|
[9602] | 82 |
|
---|
| 83 | #region OrderLine Methods
|
---|
| 84 |
|
---|
| 85 | public OrderLine FindOrderLineById(long id) {
|
---|
[9645] | 86 | using (var context = CreateContext()) {
|
---|
[9602] | 87 | return context.OrderLines.FirstOrDefault(ol => ol.OrderLineId == id);
|
---|
[9645] | 88 | }
|
---|
[9602] | 89 | }
|
---|
| 90 |
|
---|
| 91 | public IEnumerable<OrderLine> FindOrderLineBy(Expression<Func<OrderLine, bool>> predicate) {
|
---|
| 92 | using (var context = CreateContext()) {
|
---|
| 93 | var orderLines = context.OrderLines.Where(predicate).ToList();
|
---|
| 94 | return orderLines;
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public IEnumerable<OrderLine> FindAllOrderLines() {
|
---|
| 99 | using (var context = CreateContext()) {
|
---|
| 100 | var orderLines = context.OrderLines.ToList();
|
---|
| 101 | return orderLines;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[9645] | 105 | public void InsertOrUpdateOrderLine(OrderLine entity) {
|
---|
| 106 | using (var context = CreateContext()) {
|
---|
| 107 | throw new NotImplementedException();
|
---|
| 108 | }
|
---|
[9602] | 109 | }
|
---|
| 110 |
|
---|
| 111 | void DeleteOrderLine(OrderLine entity) {
|
---|
[9645] | 112 | using (var context = CreateContext()) {
|
---|
| 113 | throw new NotImplementedException();
|
---|
| 114 | }
|
---|
[9602] | 115 | }
|
---|
| 116 |
|
---|
| 117 | #endregion
|
---|
| 118 |
|
---|
| 119 | #region User Methods
|
---|
| 120 |
|
---|
| 121 | public User FindUserById(long id) {
|
---|
[9645] | 122 | using (var context = CreateContext()) {
|
---|
[9602] | 123 | return context.Users.FirstOrDefault(user => user.UserId == id);
|
---|
[9645] | 124 | }
|
---|
[9602] | 125 | }
|
---|
| 126 |
|
---|
| 127 | public IEnumerable<User> FindUserBy(Expression<Func<User, bool>> predicate) {
|
---|
| 128 | using (var context = CreateContext()) {
|
---|
| 129 | var users = context.Users.Where(predicate).ToList();
|
---|
| 130 | return users;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | public IEnumerable<User> FindAllUsers() {
|
---|
| 135 | using (var context = CreateContext()) {
|
---|
| 136 | var users = context.Users.ToList();
|
---|
| 137 | return users;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[9645] | 141 | public void InsertOrUpdateUser(User entity) {
|
---|
| 142 | using (var context = CreateContext()) {
|
---|
| 143 | throw new NotImplementedException();
|
---|
| 144 | }
|
---|
[9602] | 145 | }
|
---|
| 146 |
|
---|
| 147 | void DeleteUser(User entity) {
|
---|
[9645] | 148 | using (var context = CreateContext()) {
|
---|
| 149 | throw new NotImplementedException();
|
---|
| 150 | }
|
---|
[9602] | 151 | }
|
---|
| 152 |
|
---|
| 153 | #endregion
|
---|
| 154 |
|
---|
| 155 | #region UsageRecords Methods
|
---|
| 156 |
|
---|
| 157 | public UsageRecord FindUsageRecordById(long id) {
|
---|
[9645] | 158 | using (var context = CreateContext()) {
|
---|
[9602] | 159 | return context.UsageRecords.FirstOrDefault(prod => prod.ProductId == id);
|
---|
[9645] | 160 | }
|
---|
[9602] | 161 | }
|
---|
| 162 |
|
---|
| 163 | public IEnumerable<UsageRecord> FindUsageRecordsBy(Expression<Func<UsageRecord, bool>> predicate) {
|
---|
| 164 | using (var context = CreateContext()) {
|
---|
| 165 | var records = context.UsageRecords.Where(predicate).ToList();
|
---|
| 166 | return records;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | public IEnumerable<UsageRecord> FindAllUsageRecords() {
|
---|
| 171 | using (var context = CreateContext()) {
|
---|
| 172 | var records = context.UsageRecords.ToList();
|
---|
| 173 | return records;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[9645] | 177 | public void InsertOrUpdateUsageRecord(UsageRecord entity) {
|
---|
| 178 | using (var context = CreateContext()) {
|
---|
| 179 | throw new NotImplementedException();
|
---|
| 180 | }
|
---|
[9602] | 181 | }
|
---|
| 182 |
|
---|
| 183 | void DeleteUsageRecord(UsageRecord entity) {
|
---|
[9645] | 184 | using (var context = CreateContext()) {
|
---|
| 185 | throw new NotImplementedException();
|
---|
| 186 | }
|
---|
[9602] | 187 | }
|
---|
| 188 |
|
---|
| 189 | #endregion
|
---|
| 190 |
|
---|
| 191 | #region Invoice Methods
|
---|
| 192 |
|
---|
[9645] | 193 | public void InsertOrUpdateInvoice(Invoice entity) {
|
---|
| 194 | using (var context = CreateContext()) {
|
---|
[9602] | 195 | context.Invoices.Add(entity);
|
---|
[9645] | 196 | context.ApplyStateChanges();
|
---|
[9602] | 197 | context.SaveChanges();
|
---|
[9645] | 198 | }
|
---|
[9602] | 199 | }
|
---|
| 200 |
|
---|
| 201 | public IEnumerable<Invoice> FindInvoiceBy(Expression<Func<Invoice, bool>> predicate) {
|
---|
| 202 | using (var context = CreateContext()) {
|
---|
| 203 | var invoices = context.Invoices.Where(predicate).ToList();
|
---|
| 204 | return invoices;
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | #endregion
|
---|
[9577] | 209 | }
|
---|
| 210 | }
|
---|