adminUI
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using maintenance.Data.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace maintenance.Data.Seed;
|
||||
|
||||
public static class TemplateSeeder
|
||||
{
|
||||
public static async Task SeedAsync(AppDbContext dbContext, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var defaults = new[]
|
||||
{
|
||||
new TemplateEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "generic",
|
||||
Title = "System Error",
|
||||
Body = "A system error has occurred. Please contact MAX Support.",
|
||||
SupportContactBlock = null,
|
||||
LastUpdatedBy = "system-seed",
|
||||
LastUpdatedAtUtc = DateTime.UtcNow
|
||||
},
|
||||
new TemplateEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "unavailable",
|
||||
Title = "Application Unavailable",
|
||||
Body = "MAX applications may be down for scheduled maintenance 2AM-8AM Sunday morning.\nIf you are receiving this message at any other time, please contact MAX Support.",
|
||||
SupportContactBlock = null,
|
||||
LastUpdatedBy = "system-seed",
|
||||
LastUpdatedAtUtc = DateTime.UtcNow
|
||||
},
|
||||
new TemplateEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "template",
|
||||
Title = "Error Name",
|
||||
Body = "An error has occurred. Please contact MAX Support for assistance.",
|
||||
SupportContactBlock = null,
|
||||
LastUpdatedBy = "system-seed",
|
||||
LastUpdatedAtUtc = DateTime.UtcNow
|
||||
}
|
||||
};
|
||||
|
||||
var existingNames = await dbContext.Templates
|
||||
.AsNoTracking()
|
||||
.Select(x => x.Name)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var missing = defaults
|
||||
.Where(x => !existingNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
|
||||
if (missing.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await dbContext.Templates.AddRangeAsync(missing, cancellationToken);
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user