2023-09-19 23:32:30 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-09-29 11:30:20 -05:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2023-09-19 23:32:30 -05:00
|
|
|
|
|
|
|
|
|
namespace DamageAssesment.Api.UsersAccess.Db
|
|
|
|
|
{
|
|
|
|
|
public class UsersAccessDbContext : DbContext
|
|
|
|
|
{
|
|
|
|
|
public DbSet<Db.User> Users { get; set; }
|
|
|
|
|
public DbSet<Db.Role> Roles { get; set; }
|
|
|
|
|
public DbSet<Db.Token> Tokens { get; set; }
|
2023-09-29 11:30:20 -05:00
|
|
|
|
private IConfiguration _Configuration { get; set; }
|
|
|
|
|
public UsersAccessDbContext(DbContextOptions options, IConfiguration configuration) : base(options)
|
2023-09-19 23:32:30 -05:00
|
|
|
|
{
|
2023-09-29 11:30:20 -05:00
|
|
|
|
_Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
|
|
|
|
{
|
|
|
|
|
// connect to sql server with connection string from app settings
|
|
|
|
|
options.UseSqlServer(_Configuration.GetConnectionString("UsersAccessConnection"));
|
2023-09-19 23:32:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<User>()
|
|
|
|
|
.Property(item => item.Id)
|
|
|
|
|
.ValueGeneratedOnAdd();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Role>()
|
|
|
|
|
.Property(item => item.Id)
|
|
|
|
|
.ValueGeneratedOnAdd();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Token>()
|
|
|
|
|
.Property(item => item.Id)
|
|
|
|
|
.ValueGeneratedOnAdd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|