private static void SeedOrderStatuses(HotPointDbContext db) { var statuses = Shared.OrderStatus.GetAll <Shared.OrderStatus>().OrderBy(s => s.Id); foreach (var status in statuses) { if (!db.OrderStatuses.Any(os => os.Id == status.Id)) { var newOrderStatus = new Entities.OrderStatus() { Id = status.Id, Description = status.Name }; db.OrderStatuses.Add(newOrderStatus); } } db.SaveChanges(); }
private static void SeedEntity <E>(HotPointDbContext db, string filePath) where E : SeededEntity { var dbSet = db.Set <E>(); if (dbSet.Any()) { return; } string execPath = Assembly.GetExecutingAssembly().Location; string basePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(execPath), Constants.App.PathCorrection)); string fullPath = Path.Combine(basePath, filePath); var jsonData = File.ReadAllText(fullPath); var entityData = JsonConvert.DeserializeObject <E[]>(jsonData); dbSet.AddRange(entityData); db.SaveChanges(); }