Merge branch 'develop' into working
This commit is contained in:
commit
e2106f9a16
3 changed files with 51 additions and 1 deletions
|
|
@ -309,7 +309,57 @@ namespace BMA.EHR.Recurit.Exam.Service.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static async Task SeedPeriodExamAsync(WebApplication app)
|
||||||
|
{
|
||||||
|
using var scope = app.Services.CreateScope();
|
||||||
|
var service = scope.ServiceProvider.GetRequiredService<PeriodExamService>();
|
||||||
|
|
||||||
|
var insertedPeriodExam = new List<PeriodExam>();
|
||||||
|
|
||||||
|
if ((await service.GetsAsync()).Count() == 0)
|
||||||
|
{
|
||||||
|
// read excels into object
|
||||||
|
var excelFile = "SeedPeriodExam.xlsx";
|
||||||
|
using (var excel = new ExcelPackage(new FileInfo(excelFile)))
|
||||||
|
{
|
||||||
|
// 1. Seed PeriodExam
|
||||||
|
var workSheet = excel.Workbook.Worksheets.FirstOrDefault(x => x.Name.ToLower() == "periodexam");
|
||||||
|
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 PeriodExam = insertedPeriodExam.Where(x => x.Name == (workSheet?.Cells[row, 1]?.GetValue<string>() ?? "")).FirstOrDefault();
|
||||||
|
if (PeriodExam == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
var inserted = new PeriodExam
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = workSheet?.Cells[row, 1]?.GetValue<string>() ?? "",
|
||||||
|
Round = workSheet?.Cells[row, 2]?.GetValue<int>() ?? 0,
|
||||||
|
Fee = workSheet?.Cells[row, 3]?.GetValue<float>() ?? 0,
|
||||||
|
StartDate = workSheet?.Cells[row, 4]?.GetValue<DateTime>() ?? DateTime.Now.Date,
|
||||||
|
EndDate = workSheet?.Cells[row, 5]?.GetValue<DateTime>() ?? DateTime.Now.Date,
|
||||||
|
Year = workSheet?.Cells[row, 6]?.GetValue<int>() ?? 0,
|
||||||
|
AnnounceDate = workSheet?.Cells[row, 7]?.GetValue<DateTime>() ?? DateTime.Now.Date,
|
||||||
|
IsActive = true,
|
||||||
|
CreatedFullName = "System Administrator",
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
};
|
||||||
|
insertedPeriodExam.Add(inserted);
|
||||||
|
|
||||||
|
await service.CreateAsync(inserted);
|
||||||
|
}
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ await DatabaseSeeder.SeedEducationLevelAsync(app);
|
||||||
await DatabaseSeeder.SeedReligionAsync(app);
|
await DatabaseSeeder.SeedReligionAsync(app);
|
||||||
await DatabaseSeeder.SeedRelationshipAsync(app);
|
await DatabaseSeeder.SeedRelationshipAsync(app);
|
||||||
await DatabaseSeeder.SeedProvinceAsync(app);
|
await DatabaseSeeder.SeedProvinceAsync(app);
|
||||||
|
await DatabaseSeeder.SeedPeriodExamAsync(app);
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
void ConfigureLogs()
|
void ConfigureLogs()
|
||||||
|
|
|
||||||
BIN
SeedPeriodExam.xlsx
Normal file
BIN
SeedPeriodExam.xlsx
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue