Improved the DataSeeder logic in the startup process to ensure consistent and accurate seeding of initial data.
This commit is contained in:
parent
7c3b777c77
commit
c60bc8a9e5
@ -51,13 +51,13 @@ namespace Marco.Pms.Services.Service
|
|||||||
TenantId = Guid.Parse("b3466e83-7e11-464c-b93a-daf047838b26"),
|
TenantId = Guid.Parse("b3466e83-7e11-464c-b93a-daf047838b26"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!await dbContext.JobRoles.AnyAsync())
|
if (!await dbContext.JobRoles.Where(j => j.Name == "Admin").AnyAsync())
|
||||||
{
|
{
|
||||||
await dbContext.JobRoles.AddAsync(jobRole);
|
await dbContext.JobRoles.AddAsync(jobRole);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jobRole = await dbContext.JobRoles.FirstOrDefaultAsync();
|
jobRole = await dbContext.JobRoles.Where(j => j.Name == "Admin").FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
var role = new ApplicationRole
|
var role = new ApplicationRole
|
||||||
{
|
{
|
||||||
@ -65,13 +65,13 @@ namespace Marco.Pms.Services.Service
|
|||||||
Description = "Super User",
|
Description = "Super User",
|
||||||
TenantId = Guid.Parse("b3466e83-7e11-464c-b93a-daf047838b26")
|
TenantId = Guid.Parse("b3466e83-7e11-464c-b93a-daf047838b26")
|
||||||
};
|
};
|
||||||
if (!await dbContext.ApplicationRoles.AnyAsync())
|
if (!await dbContext.ApplicationRoles.Where(a => a.Role == "Super User").AnyAsync())
|
||||||
{
|
{
|
||||||
await dbContext.ApplicationRoles.AddAsync(role);
|
await dbContext.ApplicationRoles.AddAsync(role);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
role = await dbContext.ApplicationRoles.FirstOrDefaultAsync();
|
role = await dbContext.ApplicationRoles.Where(a => a.Role == "Super User").FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
var employee = new Employee
|
var employee = new Employee
|
||||||
@ -95,13 +95,13 @@ namespace Marco.Pms.Services.Service
|
|||||||
JobRoleId = jobRole != null ? jobRole.Id : Guid.Empty,
|
JobRoleId = jobRole != null ? jobRole.Id : Guid.Empty,
|
||||||
JoiningDate = Convert.ToDateTime("2000-04-20 10:11:17.588000"),
|
JoiningDate = Convert.ToDateTime("2000-04-20 10:11:17.588000"),
|
||||||
};
|
};
|
||||||
if ((!await dbContext.Employees.AnyAsync()) && (jobRole != null ? jobRole.Id : Guid.Empty) != Guid.Empty)
|
if ((!await dbContext.Employees.Where(e => e.FirstName == "Admin").AnyAsync()) && (jobRole != null ? jobRole.Id : Guid.Empty) != Guid.Empty)
|
||||||
{
|
{
|
||||||
await dbContext.Employees.AddAsync(employee);
|
await dbContext.Employees.AddAsync(employee);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
employee = await dbContext.Employees.FirstOrDefaultAsync();
|
employee = await dbContext.Employees.Where(e => e.FirstName == "Admin").FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
if (!await dbContext.EmployeeRoleMappings.AnyAsync())
|
if (!await dbContext.EmployeeRoleMappings.AnyAsync())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user