Changeset 9602 for branches/OaaS
- Timestamp:
- 06/10/13 16:32:19 (11 years ago)
- Location:
- branches/OaaS
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/HeuristicLab.Services.Optimization.Billing.Test.csproj
r9579 r9602 62 62 <None Include="packages.config" /> 63 63 </ItemGroup> 64 <ItemGroup> 65 <Content Include="DDLScript.sql" /> 66 </ItemGroup> 64 67 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 65 68 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/Program.cs
r9579 r9602 1 1 using System; 2 using System.Data.Entity.Infrastructure; 3 using System.IO; 2 4 using HeuristicLab.Services.Optimization.Billing.DataAccess; 3 5 using HeuristicLab.Services.Optimization.Billing.Model; … … 6 8 class Program { 7 9 static void Main(string[] args) { 10 string ddlScript; 8 11 using (var context = new BillingContext()) { 9 12 System.Data.Entity.Database.SetInitializer(new HeuristicLab.Services.Optimization.Billing.DataAccess.BillingContext.BillingContextInitiliazer()); 13 ddlScript = (((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript()); 14 } 15 16 using (StreamWriter writer = new StreamWriter(@"..\..\DDLScript.sql")) { 17 writer.Write(ddlScript); 10 18 } 11 19 -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs
r9586 r9602 45 45 } 46 46 47 public IList<Order> GetOrders(string userName) { 48 //TODO: Authentication 49 //TODO: Enable Transaction 50 User user = GetUser(userName); 51 return BillingDao.FindOrderBy(order => order.User == user).ToList(); 52 } 53 47 54 #endregion 48 55 49 50 public IList<Order> GetOrders(string userName) { 51 throw new System.NotImplementedException(); 52 } 53 56 #region User Methods 54 57 55 58 public User GetUser(string userName) { 56 throw new System.NotImplementedException(); 59 //TODO: Authentication 60 //TODO: Enable Transaction 61 return BillingDao.FindUserBy(u => u.Name == userName).First(); 57 62 } 58 63 59 64 public void SaveUser(User user) { 60 throw new System.NotImplementedException(); 65 //TODO: Authentication 66 //TODO: Enable Transaction 67 BillingDao.AddUser(user); 61 68 } 62 69 70 #endregion 71 72 #region UsageRecords Methods 63 73 64 74 public IList<UsageRecord> GetUsageRecords(string userName) { 65 throw new System.NotImplementedException(); 75 //TODO: Authentication 76 //TODO: Enable Transaction 77 User user = GetUser(userName); 78 return BillingDao.FindUsageRecordsBy(ur => ur.User == user).ToList(); 66 79 } 67 80 81 #endregion 82 83 #region Invoice Methods 68 84 69 85 public IList<Invoice> GetInvoices(string userName) { 70 throw new System.NotImplementedException(); 86 //TODO: Authentication 87 //TODO: Enable Transaction 88 User user = GetUser(userName); 89 return BillingDao.FindInvoiceBy(inv => inv.User == user).ToList(); 71 90 } 91 92 #endregion 72 93 } 73 94 } -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs
r9586 r9602 1 using System.Collections.Generic; 1 using System; 2 using System.Collections.Generic; 2 3 using System.Linq; 3 4 using HeuristicLab.Services.Optimization.Billing.Interfaces; 4 using System;5 5 6 6 namespace HeuristicLab.Services.Optimization.Billing.Business { … … 69 69 orders.Add(order); 70 70 allOrders.Add(order); 71 } 72 else { 71 } else { 73 72 oldOrder.Invoices = order.Invoices; 74 73 oldOrder.OrderLines = order.OrderLines; 75 oldOrder.OrderStateId = order.OrderStateId;76 74 oldOrder.State = order.State; 77 75 oldOrder.ActiveSince = order.ActiveSince; -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs
r9579 r9602 1 using System.Data.Entity; 1 using System; 2 using System.Collections.Generic; 3 using System.Data.Entity; 2 4 using System.Data.Entity.ModelConfiguration; 3 5 using System.Data.Entity.ModelConfiguration.Conventions; … … 6 8 namespace HeuristicLab.Services.Optimization.Billing.DataAccess { 7 9 public class BillingContext : DbContext { 8 public DbSet<ContactInformation> ContactInformations { get; set; }9 10 public DbSet<Product> Products { get; set; } 10 11 public DbSet<User> Users { get; set; } … … 14 15 public DbSet<InvoiceLine> InvoiceLines { get; set; } 15 16 public DbSet<UsageRecord> UsageRecords { get; set; } 17 public DbSet<ContactInformation> ContactInformations { get; set; } 18 public DbSet<PaymentInformation> PaymentInformations { get; set; } 16 19 17 20 // enum PaymentMethod … … 19 22 20 23 public BillingContext() 21 : base("name=BillingContext") {24 : this("name=BillingContext") { 22 25 23 26 } … … 34 37 modelBuilder.Configurations.Add(new InvoiceLineConfiguration()); 35 38 modelBuilder.Configurations.Add(new UsageRecordConfiguration()); 39 modelBuilder.Configurations.Add(new UserConfiguration()); 36 40 37 41 modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>(); … … 77 81 } 78 82 83 private class UserConfiguration : EntityTypeConfiguration<User> { 84 internal UserConfiguration() { 85 this.HasMany(u => u.PaymentInformation).WithRequired(pi => pi.User).HasForeignKey(pi => pi.UserId); 86 } 87 } 88 79 89 #endregion 80 90 81 91 #region DB Seed Methods 82 92 83 public class BillingContextInitiliazer : DropCreateDatabaseIfModelChanges<BillingContext> { 93 // - DropCreateDatabaseAlways<BillingContext> 94 // - DropCreateDatabaseIfModelChanges<BillingContext> 95 public class BillingContextInitiliazer : DropCreateDatabaseAlways<BillingContext> { 84 96 protected override void Seed(BillingContext context) { 85 context.Products.Add(new Model.Product() {97 Product p1 = new Product() { 86 98 Name = "Optimization-as-a-Service - Experiment execution", 87 99 Description = "Create and run your experiments within HeuristicLab Hive", … … 89 101 Price = 10.0, 90 102 ProductType = "Optimization Service" 91 }); 103 }; 104 p1 = context.Products.Add(p1); 105 106 User u1 = new Model.User() { Name = "spimming" }; 107 User u2 = new Model.User() { 108 Name = "fschoeppl", 109 PaymentInformation = new List<PaymentInformation>() { 110 new PaymentInformation() { 111 PaymentMethod = PaymentMethod.Visa, 112 CardNumber = "123456789" } } 113 }; 114 115 u1 = context.Users.Add(u1); 116 u2 = context.Users.Add(u2); 117 118 ContactInformation ci1 = new ContactInformation() { 119 FirstName = "Max", 120 LastName = "Mustermann", 121 Email = "max.mustermann@fh-hagenberg.at", 122 OrganizationName = "University of Applied Sciences Upper Austria School of Informatics/Communications/Media", 123 Street = "Softwarepark 11", 124 PostalCode = "4232", 125 City = "Hagenberg" 126 }; 127 128 ci1 = context.ContactInformations.Add(ci1); 129 130 Order o1 = new Order() { 131 User = u2, 132 State = OrderState.Created, 133 BillingType = BillingType.Post, 134 BillingPeriod = BillingPeriod.Monthly, 135 }; 136 OrderLine ol1 = new OrderLine() { 137 Order = o1, 138 Product = p1, 139 ProductPrice = p1.Price, 140 Quantity = 1 141 }; 142 o1 = context.Orders.Add(o1); 143 ol1 = context.OrderLines.Add(ol1); 144 145 context.SaveChanges(); 146 147 o1.State = OrderState.Active; 148 o1.ActiveSince = DateTime.Now; 149 context.Entry(o1).State = System.Data.EntityState.Modified; 92 150 context.SaveChanges(); 93 151 } -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs
r9577 r9602 111 111 112 112 #endregion 113 114 #region OrderLine Methods 115 116 public OrderLine FindOrderLineById(long id) { 117 return ExecuteWithContext<OrderLine>((context) => { 118 return context.OrderLines.FirstOrDefault(ol => ol.OrderLineId == id); 119 }); 120 } 121 122 public IEnumerable<OrderLine> FindOrderLineBy(Expression<Func<OrderLine, bool>> predicate) { 123 using (var context = CreateContext()) { 124 var orderLines = context.OrderLines.Where(predicate).ToList(); 125 return orderLines; 126 } 127 } 128 129 public IEnumerable<OrderLine> FindAllOrderLines() { 130 using (var context = CreateContext()) { 131 var orderLines = context.OrderLines.ToList(); 132 return orderLines; 133 } 134 } 135 136 public void AddOrderLine(OrderLine entity) { 137 ExecuteWithContext((context) => { 138 context.OrderLines.Add(entity); 139 context.SaveChanges(); 140 }); 141 } 142 143 public void UpdateOrderLine(OrderLine entity) { 144 ExecuteWithContext((context) => { 145 context.OrderLines.Attach(entity); 146 context.Entry(entity).State = System.Data.EntityState.Modified; 147 context.SaveChanges(); 148 }); 149 } 150 151 void DeleteOrderLine(OrderLine entity) { 152 ExecuteWithContext((context) => { 153 context.OrderLines.Remove(entity); 154 }); 155 } 156 157 #endregion 158 159 #region User Methods 160 161 public User FindUserById(long id) { 162 return ExecuteWithContext<User>((context) => { 163 return context.Users.FirstOrDefault(user => user.UserId == id); 164 }); 165 } 166 167 public IEnumerable<User> FindUserBy(Expression<Func<User, bool>> predicate) { 168 using (var context = CreateContext()) { 169 var users = context.Users.Where(predicate).ToList(); 170 return users; 171 } 172 } 173 174 public IEnumerable<User> FindAllUsers() { 175 using (var context = CreateContext()) { 176 var users = context.Users.ToList(); 177 return users; 178 } 179 } 180 181 public void AddUser(User entity) { 182 ExecuteWithContext((context) => { 183 context.Users.Add(entity); 184 context.SaveChanges(); 185 }); 186 } 187 188 public void UpdateUser(User entity) { 189 ExecuteWithContext((context) => { 190 context.Users.Attach(entity); 191 context.Entry(entity).State = System.Data.EntityState.Modified; 192 context.SaveChanges(); 193 }); 194 } 195 196 void DeleteUser(User entity) { 197 ExecuteWithContext((context) => { 198 context.Users.Remove(entity); 199 }); 200 } 201 202 #endregion 203 204 #region UsageRecords Methods 205 206 public UsageRecord FindUsageRecordById(long id) { 207 return ExecuteWithContext<UsageRecord>((context) => { 208 return context.UsageRecords.FirstOrDefault(prod => prod.ProductId == id); 209 }); 210 } 211 212 public IEnumerable<UsageRecord> FindUsageRecordsBy(Expression<Func<UsageRecord, bool>> predicate) { 213 using (var context = CreateContext()) { 214 var records = context.UsageRecords.Where(predicate).ToList(); 215 return records; 216 } 217 } 218 219 public IEnumerable<UsageRecord> FindAllUsageRecords() { 220 using (var context = CreateContext()) { 221 var records = context.UsageRecords.ToList(); 222 return records; 223 } 224 } 225 226 public void AddUsageRecord(UsageRecord entity) { 227 ExecuteWithContext((context) => { 228 context.UsageRecords.Add(entity); 229 context.SaveChanges(); 230 }); 231 } 232 233 public void UpdateUsageRecord(UsageRecord entity) { 234 ExecuteWithContext((context) => { 235 context.UsageRecords.Attach(entity); 236 context.Entry(entity).State = System.Data.EntityState.Modified; 237 context.SaveChanges(); 238 }); 239 } 240 241 void DeleteUsageRecord(UsageRecord entity) { 242 ExecuteWithContext((context) => { 243 context.UsageRecords.Remove(entity); 244 }); 245 } 246 247 #endregion 248 249 #region Invoice Methods 250 251 public void AddInvoice(Invoice entity) { 252 ExecuteWithContext((context) => { 253 context.Invoices.Add(entity); 254 context.SaveChanges(); 255 }); 256 } 257 258 public IEnumerable<Invoice> FindInvoiceBy(Expression<Func<Invoice, bool>> predicate) { 259 using (var context = CreateContext()) { 260 var invoices = context.Invoices.Where(predicate).ToList(); 261 return invoices; 262 } 263 } 264 265 #endregion 113 266 } 114 267 } -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/HeuristicLab.Services.Optimization.Billing.csproj
r9576 r9602 37 37 <Reference Include="System" /> 38 38 <Reference Include="System.ComponentModel.DataAnnotations" /> 39 <Reference Include="System.Configuration" /> 39 40 <Reference Include="System.Core" /> 40 41 <Reference Include="System.Data.Entity" /> -
branches/OaaS/HeuristicLab.Services.Optimization.Billing/Model/Model.cs
r9586 r9602 1 using System; 1 2 using System; 2 3 using System.Collections.Generic; 4 namespace HeuristicLab.Services.Optimization.Billing.Model { 3 5 4 namespace HeuristicLab.Services.Optimization.Billing.Model { 6 /* 7 * Note: enum support 8 * Although we use EF5 enums are not supported as we target .NET 4.0. 9 * Therefor we use the following workaround: 10 * Just create an int property on your class to represent the int value of the enum. 11 * That's the property that EF should map, then have a "mini wrapper" property to allow you to use the enum 12 * For example see class PaymentInformation 13 * See also: http://stackoverflow.com/questions/6344032/enums-with-ef-code-first-standard-method-to-seeding-db-and-then-using 14 */ 15 5 16 public class ContactInformation { 6 17 public long ContactInformationId { get; set; } … … 17 28 public class PaymentInformation { 18 29 public long PaymentInformationId { get; set; } 30 public long UserId { get; set; } 19 31 public string CardNumber { get; set; } 20 public PaymentMethod PaymentMethod{ get; set; }32 public int PaymentMethodValue { get; set; } 21 33 public string AdditionalInformation { get; set; } 34 35 public virtual User User { get; set; } 36 37 public PaymentMethod PaymentMethod { 38 get { return (PaymentMethod)PaymentMethodValue; } 39 set { PaymentMethodValue = (int)value; } 40 } 22 41 } 23 42 … … 52 71 public long UserId { get; set; } 53 72 public string Name { get; set; } 73 54 74 public virtual IList<PaymentInformation> PaymentInformation { get; set; } 75 55 76 } 56 77 … … 66 87 public long OrderId { get; set; } 67 88 public long UserId { get; set; } 68 public BillingType BillingType { get; set; }69 public long OrderStateId{ get; set; }70 public BillingPeriod BillingPeriod{ get; set; }89 public int StateValue { get; set; } 90 public int BillingTypeValue { get; set; } 91 public int BillingPeriodValue { get; set; } 71 92 public DateTime? ActiveSince { get; set; } 72 93 public DateTime? ActiveUntil { get; set; } 73 94 74 75 95 public virtual User User { get; set; } 76 public virtual OrderState State { get; set; }77 96 public virtual IList<Invoice> Invoices { get; set; } 78 97 public virtual IList<OrderLine> OrderLines { get; set; } 98 99 public OrderState State { 100 get { return (OrderState)StateValue; } 101 set { StateValue = (int)value; } 102 } 103 public BillingType BillingType { 104 get { return (BillingType)BillingTypeValue; } 105 set { BillingTypeValue = (int)value; } 106 } 107 public BillingPeriod BillingPeriod { 108 get { return (BillingPeriod)BillingPeriodValue; } 109 set { BillingPeriodValue = (int)value; } 110 } 79 111 } 80 112 … … 99 131 public long OrderId { get; set; } 100 132 public DateTime Due { get; set; } 101 public InvoiceStatus Status{ get; set; }133 public int StatusValue { get; set; } 102 134 public string InvoiceDocument { get; set; } 103 135 … … 105 137 public virtual Order Order { get; set; } 106 138 public virtual IList<InvoiceLine> InvoiceLines { get; set; } 139 140 public InvoiceStatus Status { 141 get { return (InvoiceStatus)StatusValue; } 142 set { StatusValue = (int)value; } 143 } 107 144 } 108 145
Note: See TracChangeset
for help on using the changeset viewer.