Files
DRS9.DashboardServer/src/DRS9.Dashboard.Infrastructure/Data/DataSeeder.cs
2026-01-13 13:50:27 +08:00

45 lines
1.8 KiB
C#

using DRS9.Dashboard.Domain.Entities;
namespace DRS9.Dashboard.Infrastructure.Data;
public static class DataSeeder
{
public static async Task SeedAsync(DashboardDbContext context)
{
// 确保数据库已创建
await context.Database.EnsureCreatedAsync();
// 添加测试设备码
if (!context.Devices.Any())
{
var devices = new List<Device>
{
new() { DeviceCode = "TEST-001-DEV", DeviceName = "测试设备1", IsEnabled = true },
new() { DeviceCode = "TEST-002-DEV", DeviceName = "测试设备2", IsEnabled = true },
new() { DeviceCode = "TEST-003-DEV", DeviceName = "测试设备3", IsEnabled = true },
new() { DeviceCode = "SCHOOL-001-DS", DeviceName = "学校显示屏1", IsEnabled = true },
new() { DeviceCode = "MALL-001-DS", DeviceName = "商场广告屏1", IsEnabled = true }
};
await context.Devices.AddRangeAsync(devices);
await context.SaveChangesAsync();
Console.WriteLine("已添加 5 个测试设备码");
}
// 添加测试应用
if (!context.Applications.Any())
{
var apps = new List<Application>
{
new() { Name = "欢迎页面", Type = "Dashboard", ContentUrl = "/dashboard/welcome", IsEnabled = true, Priority = 1 },
new() { Name = "新闻轮转", Type = "WebRotator", ContentUrl = "/rotator/news", IsEnabled = true, Priority = 2 },
new() { Name = "图片轮播", Type = "ImageRotator", ContentUrl = "/gallery/promo", IsEnabled = true, Priority = 3 }
};
await context.Applications.AddRangeAsync(apps);
await context.SaveChangesAsync();
Console.WriteLine("已添加 3 个测试应用");
}
}
}