2017-09-13 15:47:34 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using BTCPayServer.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
|
2017-09-27 22:09:59 +09:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
|
{
|
|
|
|
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
|
|
|
|
{
|
|
|
|
|
public ApplicationDbContext()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
|
|
|
|
: base(options)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<InvoiceData> Invoices
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<RefundAddressesData> RefundAddresses
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<PaymentData> Payments
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<StoreData> Stores
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
2017-09-13 23:50:36 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<UserStore> UserStore
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
2017-09-27 14:18:09 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<SettingData> Settings
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
2017-09-27 22:09:59 +09:00
|
|
|
|
var isConfigured = optionsBuilder.Options.Extensions.OfType<RelationalOptionsExtension>().Any();
|
|
|
|
|
if(!isConfigured)
|
2017-09-13 15:47:34 +09:00
|
|
|
|
optionsBuilder.UseSqlite("Data Source=temp.db");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
base.OnModelCreating(builder);
|
|
|
|
|
builder.Entity<InvoiceData>()
|
|
|
|
|
.HasIndex(o => o.StoreDataId);
|
|
|
|
|
|
|
|
|
|
builder.Entity<PaymentData>()
|
|
|
|
|
.HasIndex(o => o.InvoiceDataId);
|
|
|
|
|
|
|
|
|
|
builder.Entity<RefundAddressesData>()
|
|
|
|
|
.HasIndex(o => o.InvoiceDataId);
|
|
|
|
|
|
|
|
|
|
builder.Entity<UserStore>()
|
2017-09-27 22:09:59 +09:00
|
|
|
|
.HasKey(t => new
|
|
|
|
|
{
|
2017-09-13 15:47:34 +09:00
|
|
|
|
t.ApplicationUserId,
|
|
|
|
|
t.StoreDataId
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.Entity<UserStore>()
|
|
|
|
|
.HasOne(pt => pt.ApplicationUser)
|
|
|
|
|
.WithMany(p => p.UserStores)
|
|
|
|
|
.HasForeignKey(pt => pt.ApplicationUserId);
|
|
|
|
|
|
|
|
|
|
builder.Entity<UserStore>()
|
|
|
|
|
.HasOne(pt => pt.StoreData)
|
|
|
|
|
.WithMany(t => t.UserStores)
|
|
|
|
|
.HasForeignKey(pt => pt.StoreDataId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|