Refactor EnvelopeHistory and update DbContext for migrations
Removed Sender and Receiver properties from EnvelopeHistory. Added ActionDate and Comment properties. Introduced IsMigration property in EGDbContext to conditionally configure foreign key relationships for EnvelopeHistory. Updated EGDbContextFactory to set IsMigration during context creation for migration operations.
This commit is contained in:
parent
349d65d050
commit
9a9aa2608b
@ -38,10 +38,8 @@ namespace EnvelopeGenerator.Domain.Entities
|
||||
[Column("COMMENT", TypeName = "nvarchar(max)")]
|
||||
public string Comment { get; set; }
|
||||
|
||||
[ForeignKey("UserReference")]
|
||||
public virtual User Sender { get; set; }
|
||||
|
||||
[ForeignKey("UserReference")]
|
||||
public virtual Receiver Receiver { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
|
||||
@ -61,6 +61,8 @@ public class EGDbContext : DbContext, IUserManagerDbContext, IMailDbContext
|
||||
|
||||
private readonly ILogger<EGDbContext>? _logger;
|
||||
|
||||
public bool IsMigration { get; set; } = false;
|
||||
|
||||
public EGDbContext(DbContextOptions<EGDbContext> options, IOptions<DbTriggerParams> triggerParamOptions, ILogger<EGDbContext>? logger = null) : base(options)
|
||||
{
|
||||
_triggers = triggerParamOptions.Value;
|
||||
@ -126,17 +128,20 @@ public class EGDbContext : DbContext, IUserManagerDbContext, IMailDbContext
|
||||
.WithMany(ed => ed.Elements)
|
||||
.HasForeignKey(dre => dre.DocumentId);
|
||||
|
||||
modelBuilder.Entity<EnvelopeHistory>()
|
||||
.HasOne(eh => eh.Receiver)
|
||||
.WithMany()
|
||||
.HasForeignKey(eh => eh.UserReference)
|
||||
.HasPrincipalKey(e => e.EmailAddress);
|
||||
if (!IsMigration)
|
||||
{
|
||||
modelBuilder.Entity<EnvelopeHistory>()
|
||||
.HasOne(eh => eh.Receiver)
|
||||
.WithMany()
|
||||
.HasForeignKey(eh => eh.UserReference)
|
||||
.HasPrincipalKey(e => e.EmailAddress);
|
||||
|
||||
modelBuilder.Entity<EnvelopeHistory>()
|
||||
.HasOne(eh => eh.Sender)
|
||||
.WithMany()
|
||||
.HasForeignKey(eh => eh.UserReference)
|
||||
.HasPrincipalKey(e => e.Email);
|
||||
modelBuilder.Entity<EnvelopeHistory>()
|
||||
.HasOne(eh => eh.Sender)
|
||||
.WithMany()
|
||||
.HasForeignKey(eh => eh.UserReference)
|
||||
.HasPrincipalKey(e => e.Email);
|
||||
}
|
||||
|
||||
modelBuilder.Entity<EnvelopeReceiverReadOnly>()
|
||||
.HasOne(erro => erro.Receiver)
|
||||
|
||||
@ -38,7 +38,9 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
}
|
||||
}
|
||||
|
||||
return new EGDbContext(optionsBuilder.Options, Options.Create(dbTriggerParams));
|
||||
var dbContext = new EGDbContext(optionsBuilder.Options, Options.Create(dbTriggerParams));
|
||||
dbContext.IsMigration = true;
|
||||
return dbContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user