Files
Auth/Auth.Domain/Context.cs
T
2026-08-05 21:15:14 +03:00

130 lines
4.3 KiB
C#
Executable File

using Auth.Domain.Entities;
using Auth.Domain.Entities.HR;
using Bogus;
// using Domain.Configuration;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Auth.Domain;
public class Context : IdentityDbContext
{
public Context(DbContextOptions<Context> options)
: base(options) { }
// public DbSet<Product> Products { get; set; }
public DbSet<AppUser> AppUsers { get; set; }
public DbSet<Role> Roles { get; set; }
// public DbSet<Salary> Salaries { get; set; }
// public DbSet<Category> Categories { get; set; }
// public DbSet<Order> Orders { get; set; }
// public DbSet<ItemOrder> ItemOrders { get; set; }
// public DbSet<Bill> Bills { get; set; }
// public DbSet<BillType> BillTypes { get; set; }
// public DbSet<Role> Roles { get; set; }
// public DbSet<Shipping> Shippings { get; set; }
// public DbSet<Bundle> Bundles { get; set; }
// public DbSet<Request> Requests { get; set; }
// public DbSet<Purchase> Purchases { get; set; }
// public DbSet<StoreItem> StoreItems { get; set; }
// public DbSet<InventoryOrder> InventoryOrders { get; set; }
// public DbSet<Delivery> Deliveries { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.ConfigureWarnings(warnings =>
warnings.Ignore(RelationalEventId.PendingModelChangesWarning)
);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var password = new PasswordHasher<AppUser>();
var superAdmin = new AppUser()
{
Id = Guid.NewGuid().ToString(),
Name = "said",
Email = "said.amir.kattan@outlook.com",
UserName = "said.amir.kattan@outlook.com",
NormalizedEmail = "said.amir.kattan@outlook.com".ToUpper(),
NormalizedUserName = "said.amir.kattan@outlook.com".ToUpper(),
Building = "Building 123",
PhoneNumber = "01231231322",
PhotoPath = "Test",
EmailConfirmed = true,
Holidays = 2,
PasswordHash = password.HashPassword(null, "aaa111!!!AAA"),
// Roles = new List<string>() {}
};
var standardRole = new IdentityRole()
{
Id = Guid.NewGuid().ToString(),
Name = "User",
NormalizedName = "User".ToUpper(),
ConcurrencyStamp = Guid.NewGuid().ToString(),
};
var moderatorRole = new IdentityRole()
{
Id = Guid.NewGuid().ToString(),
Name = "Moderator",
NormalizedName = "moderator".ToUpper(),
ConcurrencyStamp = Guid.NewGuid().ToString(),
};
var AdminRole = new IdentityRole()
{
Id = Guid.NewGuid().ToString(),
Name = "Admin",
NormalizedName = "Admin".ToUpper(),
ConcurrencyStamp = Guid.NewGuid().ToString(),
};
var superAdminRole = new IdentityRole()
{
Id = Guid.NewGuid().ToString(),
Name = "SuperAdmin",
NormalizedName = "superAdmin".ToUpper(),
ConcurrencyStamp = Guid.NewGuid().ToString(),
};
var userRole = new IdentityUserRole<string>()
{
RoleId = superAdminRole.Id,
UserId = superAdmin.Id,
};
modelBuilder.Entity<AppUser>().HasData(superAdmin);
modelBuilder
.Entity<IdentityRole>()
.HasData(standardRole, moderatorRole, AdminRole, superAdminRole);
modelBuilder.Entity<IdentityUserRole<string>>().HasData(userRole);
// var users = new UserConfiguration(300);
// modelBuilder.Entity<AppUser>().HasData(users);
// var categoryCount = 30;
//modelBuilder.Entity<Product>().HasData(productsList);
// modelBuilder.ApplyConfiguration(new CategoryConfiguration(categoryCount));
// modelBuilder.ApplyConfiguration(new ProductConfiguration(1000, categoryCount));
// modelBuilder.ApplyConfiguration(new ShippingConfiguration());
// modelBuilder.ApplyConfiguration(new BundleConfiguration(50));
}
}