WebUI Redesign and Component 1: category mapper fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Predictalytics.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Predictalytics.Infrastructure.Data;
|
||||
|
||||
@@ -25,7 +26,49 @@ public class AppDbContext : DbContext
|
||||
public DbSet<TraderTrait> TraderTraits => Set<TraderTrait>();
|
||||
public DbSet<TraderWindowMetrics> TraderWindowMetrics => Set<TraderWindowMetrics>();
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||
private readonly bool _isReadOnly;
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options, Microsoft.Extensions.Configuration.IConfiguration? configuration = null)
|
||||
: base(options)
|
||||
{
|
||||
_isReadOnly = configuration?.GetValue<bool>("ApiSettings:ReadOnlyDatabase", false) ?? false;
|
||||
}
|
||||
|
||||
public override int SaveChanges()
|
||||
{
|
||||
if (_isReadOnly)
|
||||
{
|
||||
throw new System.InvalidOperationException("Database is configured as Read-Only.");
|
||||
}
|
||||
return base.SaveChanges();
|
||||
}
|
||||
|
||||
public override int SaveChanges(bool acceptAllChangesOnSuccess)
|
||||
{
|
||||
if (_isReadOnly)
|
||||
{
|
||||
throw new System.InvalidOperationException("Database is configured as Read-Only.");
|
||||
}
|
||||
return base.SaveChanges(acceptAllChangesOnSuccess);
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_isReadOnly)
|
||||
{
|
||||
throw new System.InvalidOperationException("Database is configured as Read-Only.");
|
||||
}
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_isReadOnly)
|
||||
{
|
||||
throw new System.InvalidOperationException("Database is configured as Read-Only.");
|
||||
}
|
||||
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder mb)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user