コード例 #1
0
 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);
     }
 }
コード例 #2
0
        static HrmDbContext()
        {
            var builder = new DbContextOptionsBuilder();

            builder.UseSqlite("fake");
            using (var context = new HrmDbContext(builder.Options))
            {
                DataModel = context.Model;
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 public HrmContext(HrmDbContext db, ClaimsPrincipal user, List <DateTime> holidays)
 {
     DbContext   = db;
     UserContext = user;
     Holidays    = holidays;
 }