public static void SeedData(this HrmDbContext db) { db.Database.EnsureCreated(); if (db.Holidays.Count() == 0) { var json = File.ReadAllText("InitData/Holidays.json"); var data = JArray.Parse(json).ToObject<List<HolidayDTO>>(); db.ImportHoliday(data); } }
static HrmDbContext() { var builder = new DbContextOptionsBuilder(); builder.UseSqlite("fake"); using (var context = new HrmDbContext(builder.Options)) { DataModel = context.Model; } }
public static int ImportHoliday(this HrmDbContext db, List<HolidayDTO> data) { var holidays = db.Holidays.Select(x => x.Value.Date).ToList(); var toImport = data.Where(x => x.IsHoliday == "是") .Where(x => !holidays.Contains(x.Date.Date)) .Select(x => new Holiday() { Name = x.Name, Description = $"{x.HolidayCategory}. {x.Description}".Trim(), Value = x.Date }).ToList(); db.Holidays.AddRange(toImport); return db.SaveChanges(); }
public HrmContext(HrmDbContext db, ClaimsPrincipal user, List <DateTime> holidays) { DbContext = db; UserContext = user; Holidays = holidays; }