public IActionResult Populate() { int recordsAdded = DatabasePopulator.PopulateImageEventsDatabase(_repository); int recordsAddedEdgeDevices = DatabasePopulator.PopulateEdgeDevicesDatabase(_repository); return(Ok(recordsAdded)); }
// Main() boots up a web server and the host for this project. public static void Main(string[] args) { // On the line below, the Host is declared and turned on. var host = BuildWebHost(args); // Creates the scope within which this program's services and operations are // executed. using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { // POPULATE THE DATABASE // 1. Get a database context instance from the dependency injection container. var context = services.GetRequiredService <Context>(); // 2. Call the seed method, passing to it the context. DatabasePopulator.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } // 3. Dispose the context when the seed method is done and goes out of scope. } // The Host is started. host.Run(); }
public void SetUp() { this.db = new UserOrderProductDataSet(); this.pop = new DatabasePopulator(); this.pop.Populate(this.db); this.users = this.pop.Tables[this.db.Tables["Users"]]; this.orders = this.pop.Tables[this.db.Tables["Orders"]]; this.products = this.pop.Tables[this.db.Tables["Products"]]; this.orderProducts = this.pop.Tables[this.db.Tables["OrderProducts"]]; }
private void btnFeedbackLoader_Click(object sender, RoutedEventArgs e) { if (this.filePath != string.Empty) { using (var context = new CupOfCoffeeContext()) { try { var feedbacks = XmlParser.GenerateFeedbacksFromXml(this.filePath); foreach (var feedback in feedbacks) { context.CustomerFeedbacks.Add(feedback); } context.SaveChanges(); foreach (var feedback in feedbacks) { string feedbackAsJson = JsonConvert.SerializeObject(feedback); } DatabasePopulator.ImportFeedback(feedbacks); } catch (Exception) { MessageBox.Show("Cannot load the xml! Please, make sure that the data in it is correct!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } else { MessageBox.Show("There is no xml file chosen!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static void Main(string[] args) { IWebHost host = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { DatabaseContext context = services.GetRequiredService <DatabaseContext>(); DatabasePopulator.Populate(context); } catch (Exception ex) { ILogger logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
void InitializeDatabase() { #if Migrate if (MessageBox.Show("Do you want to re-build DB?", "Warning", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (var dbContext = new AppDbContext()) { dbContext.Database.EnsureDeleted(); dbContext.Database.Migrate(); } MessageBox.Show("DB Data Migration Completed!"); } #endif #if Seed if (MessageBox.Show("Do you want to populate DB?", "Warning", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { DatabasePopulator.PopulateHistoricData(); MessageBox.Show("DB Data Seeding Completed!"); } #endif }
public IActionResult Populate() { int recordsAdded = DatabasePopulator.PopulateDatabase(_repository); return(Ok(recordsAdded)); }
public void OnGet() { RecordsAdded = DatabasePopulator.PopulateDatabase(_repository); }
public Menu() { InitializeComponent(); DatabasePopulator.Seed(); }
public IActionResult PopulateSampleData() { int addedCount = DatabasePopulator.PopulateDatabase(_repository); return(Ok(addedCount)); }
public async Task OnGetAsync() { RecordsAdded = await DatabasePopulator.PopulateDatabaseAsync(_repository); }
public void OnGet() { RecordsAdded = DatabasePopulator.PopulateEdgeDevicesDatabase(_repository); RecordsAdded = DatabasePopulator.PopulateImageEventsDatabase(_repository); }
public async Task <IActionResult> Populate() { int recordsAdded = await DatabasePopulator.PopulateDatabaseAsync(_repository); return(Ok(recordsAdded)); }