Seed Default Data
This commit is contained in:
parent
109016e2b5
commit
1d7d7b261c
3 changed files with 37 additions and 0 deletions
|
|
@ -128,6 +128,7 @@ var app = builder.Build();
|
|||
|
||||
// seed default data
|
||||
await CommandDataSeeder.SeedData(app);
|
||||
await CommandDataSeeder.SeedCommandType(app);
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -44,5 +44,41 @@ namespace BMA.EHR.Infrastructure.Persistence
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SeedCommandType(WebApplication app)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var service = scope.ServiceProvider.GetRequiredService<CommandTypeRepository>();
|
||||
|
||||
if ((await service.GetAllAsync()).Count() == 0)
|
||||
{
|
||||
// read excels into object
|
||||
var excelFile = "SeedCommand.xlsx";
|
||||
using (var excel = new ExcelPackage(new FileInfo(excelFile)))
|
||||
{
|
||||
var workSheet = excel.Workbook.Worksheets.FirstOrDefault(x => x.Name.ToLower() == "commandtype");
|
||||
var totalRows = workSheet?.Dimension.Rows;
|
||||
|
||||
int row = 2;
|
||||
|
||||
while (row <= totalRows)
|
||||
{
|
||||
var cell1 = workSheet?.Cells[row, 1]?.GetValue<string>();
|
||||
if (cell1 == "" || cell1 == null) break;
|
||||
|
||||
var inserted = new CommandType
|
||||
{
|
||||
Id = Guid.Parse(workSheet?.Cells[row, 1]?.GetValue<string>()!),
|
||||
Name = workSheet?.Cells[row, 2]?.GetValue<string>()!,
|
||||
Category = workSheet?.Cells[row, 3]?.GetValue<string>()!
|
||||
};
|
||||
|
||||
await service.AddAsync(inserted);
|
||||
|
||||
row++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue