68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using OFBButte.Application.Database;
|
|
using OFBButte.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace OFBButte.Database
|
|
{
|
|
public class OFBContext : DbContext, IOFBContext
|
|
{
|
|
public OFBContext(DbContextOptions<OFBContext> options)
|
|
: base(options)
|
|
{ }
|
|
|
|
public static void UseMySql(DbContextOptionsBuilder optionsBuilder, string connString)
|
|
{
|
|
optionsBuilder.UseMySql(connString, ServerVersion.AutoDetect(connString));
|
|
}
|
|
|
|
public DbSet<User> Users { get; set; }
|
|
public DbSet<Profile> Profiles { get; set; }
|
|
public DbSet<ProfileFederationCode> ProfileFederationCodes { get; set; }
|
|
public DbSet<EmailVerificationCode> EmailVerificationCodes { get; set; }
|
|
public DbSet<PasswordResetCode> PasswordResetCodes { get; set; }
|
|
public DbSet<MissionarySupport> MissionarySupportForms { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<User>(e =>
|
|
{
|
|
e.HasKey(x => x.Id);
|
|
e.HasIndex(x => x.Email);
|
|
e.Property(x => x.Email).IsRequired();
|
|
e.Property(x => x.Password).IsRequired();
|
|
e.Property(x => x.CreatedDate).IsRequired();
|
|
e.HasOne(x => x.EmailVerificationCode);
|
|
e.HasOne(x => x.Profile);
|
|
e.HasOne(x => x.PassswordResetCode);
|
|
});
|
|
|
|
modelBuilder.Entity<EmailVerificationCode>(e => {
|
|
e.HasKey(x => x.Id);
|
|
});
|
|
|
|
modelBuilder.Entity<Profile>(e => {
|
|
e.HasKey(x => x.Id);
|
|
e.HasOne(x => x.ProfileFederationCode);
|
|
});
|
|
|
|
modelBuilder.Entity<ProfileFederationCode>(e => {
|
|
e.HasKey(x => x.Id);
|
|
});
|
|
|
|
modelBuilder.Entity<PasswordResetCode>(e => {
|
|
e.HasKey(x => x.Id);
|
|
});
|
|
|
|
modelBuilder.Entity<MissionarySupport>(e => {
|
|
e.HasKey(x => x.Id);
|
|
e.Ignore(x => x.HoneyPot);
|
|
});
|
|
}
|
|
}
|
|
}
|