Files
DbFirst/DbFirst.Infrastructure/ApplicationDbContext.cs
OlgunR f5224e20f2 Add time record API endpoint and supporting infrastructure
Introduced a new TimeController with a POST endpoint to insert and retrieve the latest time record. Added ITimeRepository, TimeRepository, and TimeRecord entity. Implemented MediatR command and handler for time insertion. Updated ApplicationDbContext and DI configuration to support the new feature.
2026-03-30 15:16:03 +02:00

102 lines
3.6 KiB
C#

using DbFirst.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace DbFirst.Infrastructure;
public partial class ApplicationDbContext : DbContext
{
private readonly TableConfigurations _config;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IOptionsMonitor<TableConfigurations> configOptions)
: base(options)
{
_config = configOptions.CurrentValue;
}
public virtual DbSet<VwmyCatalog> VwmyCatalogs { get; set; }
public virtual DbSet<SmfLayout> SmfLayouts { get; set; }
public virtual DbSet<TimeRecord> Times { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var catCfg = _config.VwmyCatalog;
modelBuilder.Entity<VwmyCatalog>(entity =>
{
entity.HasKey(e => e.Guid);
entity.ToView(catCfg.ViewName);
entity.Property(e => e.Guid).HasColumnName(catCfg.GuidColumnName);
entity.Property(e => e.AddedWho)
.HasMaxLength(30)
.IsUnicode(false)
.HasColumnName(catCfg.AddedWhoColumnName);
entity.Property(e => e.AddedWhen)
.HasColumnType("datetime")
.HasColumnName(catCfg.AddedWhenColumnName);
entity.Property(e => e.CatString)
.HasMaxLength(900)
.IsUnicode(false)
.HasColumnName(catCfg.CatStringColumnName);
entity.Property(e => e.CatTitle)
.HasMaxLength(100)
.IsUnicode(false)
.HasColumnName(catCfg.CatTitleColumnName);
entity.Property(e => e.ChangedWhen)
.HasColumnType("datetime")
.HasColumnName(catCfg.ChangedWhenColumnName);
entity.Property(e => e.ChangedWho)
.HasMaxLength(30)
.IsUnicode(false)
.HasColumnName(catCfg.ChangedWhoColumnName);
});
modelBuilder.Entity<SmfLayout>(entity =>
{
entity.HasKey(e => e.Guid);
entity.ToTable("TBDD_SMF_LAYOUT", tb => tb.HasTrigger("TBDD_SMF_LAYOUT_AFT_UPD"));
entity.Property(e => e.Guid).HasColumnName("GUID");
entity.Property(e => e.Active).HasColumnName("ACTIVE");
entity.Property(e => e.LayoutType)
.HasMaxLength(50)
.HasColumnName("LAYOUT_TYPE");
entity.Property(e => e.LayoutKey)
.HasMaxLength(150)
.HasColumnName("LAYOUT_KEY");
entity.Property(e => e.UserName)
.HasMaxLength(50)
.HasColumnName("USER_NAME");
entity.Property(e => e.LayoutData).HasColumnName("LAYOUT_DATA");
entity.Property(e => e.AddedWho)
.HasMaxLength(50)
.HasColumnName("ADDED_WHO");
entity.Property(e => e.AddedWhen)
.HasColumnType("datetime")
.HasColumnName("ADDED_WHEN");
entity.Property(e => e.ChangedWho)
.HasMaxLength(50)
.HasColumnName("CHANGED_WHO");
entity.Property(e => e.ChangedWhen)
.HasColumnType("datetime")
.HasColumnName("CHANGED_WHEN");
});
modelBuilder.Entity<TimeRecord>(entity =>
{
entity.HasNoKey();
entity.ToTable("TIME");
entity.Property(e => e.Now)
.HasColumnType("datetime")
.HasColumnName("NOW");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}