Add Command Controller Code (Not Complete)
This commit is contained in:
parent
9ee5b86a26
commit
7f5ed43f3f
27 changed files with 58797 additions and 84 deletions
|
|
@ -272,7 +272,7 @@ namespace BMA.EHR.Infrastructure.Persistence
|
|||
public DbSet<DeploymentChannel> DeploymentChannels { get; set; }
|
||||
|
||||
|
||||
public DbSet<PlacementCommand> PlacementCommands { get; set; }
|
||||
public DbSet<Command> Commands { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
48
BMA.EHR.Infrastructure/Persistence/CommandDataSeeder.cs
Normal file
48
BMA.EHR.Infrastructure/Persistence/CommandDataSeeder.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Domain.Models.Commands.Core;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OfficeOpenXml;
|
||||
|
||||
namespace BMA.EHR.Infrastructure.Persistence
|
||||
{
|
||||
public static class CommandDataSeeder
|
||||
{
|
||||
public static async Task SeedData(WebApplication app)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var service = scope.ServiceProvider.GetRequiredService<CommandStatusRepository>();
|
||||
|
||||
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() == "commandstatus");
|
||||
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 CommandStatus
|
||||
{
|
||||
Id = Guid.Parse(workSheet?.Cells[row, 1]?.GetValue<string>()!),
|
||||
Name = workSheet?.Cells[row, 2]?.GetValue<string>()!,
|
||||
Sequence = (int)workSheet?.Cells[row, 3]?.GetValue<int>()!
|
||||
};
|
||||
|
||||
await service.AddAsync(inserted);
|
||||
|
||||
row++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue