update
This commit is contained in:
@@ -55,7 +55,8 @@ namespace Webshop.Infrastructure.Data
|
||||
modelBuilder.Entity<Setting>().HasIndex(s => s.Key).IsUnique();
|
||||
modelBuilder.Entity<Order>().HasIndex(o => o.OrderNumber).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Product>(e => {
|
||||
modelBuilder.Entity<Product>(e =>
|
||||
{
|
||||
e.Property(p => p.Price).HasPrecision(18, 2);
|
||||
e.Property(p => p.OldPrice).HasPrecision(18, 2);
|
||||
e.Property(p => p.PurchasePrice).HasPrecision(18, 2);
|
||||
@@ -68,24 +69,28 @@ namespace Webshop.Infrastructure.Data
|
||||
modelBuilder.Entity<ProductVariant>()
|
||||
.Property(pv => pv.PriceAdjustment).HasPrecision(18, 2);
|
||||
|
||||
modelBuilder.Entity<Order>(e => {
|
||||
modelBuilder.Entity<Order>(e =>
|
||||
{
|
||||
e.Property(o => o.OrderTotal).HasPrecision(18, 2);
|
||||
e.Property(o => o.ShippingCost).HasPrecision(18, 2);
|
||||
e.Property(o => o.TaxAmount).HasPrecision(18, 2);
|
||||
e.Property(o => o.DiscountAmount).HasPrecision(18, 2);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<OrderItem>(e => {
|
||||
modelBuilder.Entity<OrderItem>(e =>
|
||||
{
|
||||
e.Property(oi => oi.UnitPrice).HasPrecision(18, 2);
|
||||
e.Property(oi => oi.TotalPrice).HasPrecision(18, 2);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Discount>(e => {
|
||||
modelBuilder.Entity<Discount>(e =>
|
||||
{
|
||||
e.Property(d => d.DiscountValue).HasPrecision(18, 2);
|
||||
e.Property(d => d.MinimumOrderAmount).HasPrecision(18, 2);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ShippingMethod>(e => {
|
||||
modelBuilder.Entity<ShippingMethod>(e =>
|
||||
{
|
||||
e.Property(sm => sm.BaseCost).HasPrecision(18, 2);
|
||||
e.Property(sm => sm.MinimumOrderAmount).HasPrecision(18, 2);
|
||||
});
|
||||
@@ -122,6 +127,11 @@ namespace Webshop.Infrastructure.Data
|
||||
.WithMany()
|
||||
.HasForeignKey(o => o.ShippingAddressId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<ApplicationUser>()
|
||||
.HasOne(a => a.Customer) // Ein ApplicationUser hat ein optionales Customer-Profil
|
||||
.WithOne(c => c.User) // Ein Customer-Profil ist mit genau einem User verknüpft
|
||||
.HasForeignKey<Customer>(c => c.AspNetUserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Webshop.Infrastructure/Data/ApplicationDbContextFactory.cs
Normal file
27
Webshop.Infrastructure/Data/ApplicationDbContextFactory.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
// In src/Webshop.Infrastructure/Data/ApplicationDbContextFactory.cs
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace Webshop.Infrastructure.Data
|
||||
{
|
||||
public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
|
||||
{
|
||||
public ApplicationDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../Webshop.Api"))
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
optionsBuilder.UseNpgsql(connectionString);
|
||||
|
||||
return new ApplicationDbContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user