public MainWindowViewModel() { GroundwaterContext groundwaterContext = new GroundwaterContext(); WellRepository wellRepository = new WellRepository(groundwaterContext); _gmaListViewModel = new GmaListViewModel(wellRepository); _aquiferListViewModel = new AquiferListViewModel(wellRepository); _countyListViewModel = new CountyListViewModel(wellRepository); _wellListViewModel = new WellListViewModel(wellRepository); _countyListViewModel.CheckCountyRequested += FilterCounty; _countyListViewModel.UncheckCountyRequested += FilterCounty; _gmaListViewModel.CheckGmaRequested += FilterGma; _gmaListViewModel.UncheckGmaRequested += FilterGma; _aquiferListViewModel.CheckAquiferRequested += FilterAquifer; _aquiferListViewModel.UncheckAquiferRequested += FilterAquifer; CloseCommand = new RelayCommand(OnClose); NavCommand = new RelayCommand <BindableItem>(OnNav); LoadDataCommand = new RelayCommand(OnLoadData); CurrentFilterViewModel = _countyListViewModel; ExportToCsvCommand = new RelayCommand(OnExportToCsv); Criteria = new ObservableCollection <BindableItem> { new BindableItem("County"), new BindableItem("GMA"), new BindableItem("Aquifer"), }; }
private static void LoadMainTable(string path, object sender) { TextLoader textLoader = new TextLoader(path); // Reads text into two report data containers AquiferTextReport aqReport = new AquiferTextReport(); WellTextReport wellReport = new WellTextReport(); textLoader.LoadText(aqReport, wellReport); using (var context = new GroundwaterContext()) { // loads aquifer data into database // var currentAquifers = context.Aquifers.ToList(); var aquifers = aqReport.GetUnique(); var aqCount = aquifers.Count(); int actualProgress; for (int i = 0; i < aqCount; i++) { var aq = aquifers[i]; //var retrievedAq = context.Aquifers.Find(aq.AquiferID); if (context.Aquifers.Any(e => e.AquiferID == aq.AquiferID)) { context.Entry(aq).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } else { context.Aquifers.Add(aq); } actualProgress = i * 100 / (aqCount * 2); (sender as BackgroundWorker).ReportProgress(actualProgress); } // loads well information into database var currentWells = context.Wells.ToList(); context.Wells.RemoveRange(currentWells); context.SaveChanges(); var wells = wellReport.GetAll(); var wellCount = wells.Count(); for (int i = 0; i < wellCount; i++) { var w = wells[i]; context.Wells.Add(w); actualProgress = 50 + (i * 100 / (wellCount * 2)); (sender as BackgroundWorker).ReportProgress(actualProgress); } context.SaveChanges(); (sender as BackgroundWorker).ReportProgress(100); } }
public GroundwaterContextTestBase() { var options = new DbContextOptionsBuilder <GroundwaterContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; _context = new GroundwaterContext(options); _context.Database.EnsureCreated(); var edwards = new Aquifer { AquiferID = 11, AquiferCode = "218EDRDA", AquiferCodeDescriprion = "Edwards and Associated Limestones", AquiferName = "Edwards (Balcones Fault Zone)" }; var antlers = new Aquifer { AquiferID = 13, AquiferCode = "218ALRS", AquiferCodeDescriprion = "Antlers Sand", AquiferName = "Edwards-Trinity Plateau" }; var gulfCoast = new Aquifer { AquiferID = 15, AquiferCode = "", AquiferCodeDescriprion = "", AquiferName = "Gulf Coast" }; var wells = new[] { new Well { StateWellNumber = "2217381", GMA = 10, County = "Travis", AquiferId = 11, Aquifer = edwards }, new Well { StateWellNumber = "2096010", GMA = 7, County = "Glasscock", AquiferId = 13, Aquifer = antlers }, new Well { StateWellNumber = "2173076", GMA = 16, County = "Nueces", AquiferId = 15, Aquifer = gulfCoast }, new Well { StateWellNumber = "2159993", GMA = 13, County = "Medina", AquiferId = 11, Aquifer = edwards }, new Well { StateWellNumber = "2160018", GMA = 13, County = "Atascosa", AquiferId = 11, Aquifer = edwards }, new Well { StateWellNumber = "2220063", GMA = 9, County = "Kendall", AquiferId = 13, Aquifer = antlers }, new Well { StateWellNumber = "2181848", GMA = 10, County = "Uvalde", AquiferId = 13, Aquifer = antlers }, new Well { StateWellNumber = "2184349", GMA = 10, County = "Uvalde", AquiferId = 13, Aquifer = antlers }, }; _context.Wells.AddRange(wells); _context.SaveChanges(); }
public WellRepository(GroundwaterContext context) { _context = context; }