Exemplo n.º 1
0
        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();
        }
Exemplo n.º 3
0
        public ActionResult CreateWaterIntake(WaterIntakeModel wtmodel)
        {
            Laboratory b = db.Laboratories.Find(wtmodel.LaboratoryId);
            Station    s = db.Stations.Find(wtmodel.StationId);

            if (b == null)
            {
                throw new OperationCanceledException("Laboratory not found");
            }

            if (s == null)
            {
                throw new OperationCanceledException("Station not found");
            }

            WaterIntake wt = WaterIntakeModelToWaterIntakeMap(wtmodel);

            wt.Laboratory = b;
            wt.Station    = s;

            Chemical     ch = WaterIntakeModelToChemical(wtmodel);
            Organoleptic or = WaterIntakeModelToOrganoleptic(wtmodel);

            if (ModelState.IsValid)
            {
                if (wtmodel.LaboratoryDate == null)
                {
                    wt.Status = DAL.Status.taken;
                }
                else
                {
                    wt.Status = DAL.Status.investigated;
                }

                s.Class = CheckingClass(ch, or);

                db.WaterIntakes.Add(wt);
                db.Chemicals.Add(ch);
                db.Organoleptics.Add(or);
                db.SaveChanges();

                return(RedirectToAction("WaterIntakes"));
            }
            else
            {
                WaterIntakeViewBag();

                if (wtmodel.IntakeDate == default(DateTime))
                {
                    ViewBag.IntakeDate = DateTime.Now;
                }
                else
                {
                    ViewBag.IntakeDate = wtmodel.IntakeDate;
                }

                if (wtmodel.LaboratoryDate == default(DateTime))
                {
                    ViewBag.LaboratoryDate = DateTime.Now;
                }
                else
                {
                    ViewBag.LaboratoryDate = wtmodel.LaboratoryDate;
                }

                return(View(wtmodel));
            }
        }