示例#1
0
        public async Task <Well> UpdateWellAsync(Well well)
        {
            if (!_context.Wells.Local.Any(w => w.WellId == well.WellId))
            {
                _context.Wells.Attach(well);
            }
            _context.Entry(well).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(well);
        }
示例#2
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);
            }
        }
示例#3
0
        public ActionResult EditWaterIntake(WaterIntakeModel wtmodel)
        {
            if (ModelState.IsValid)
            {
                WaterIntake wt = new WaterIntake()
                {
                    Id             = wtmodel.Id,
                    LaboratoryId   = wtmodel.LaboratoryId,
                    IntakeDate     = wtmodel.IntakeDate,
                    LaboratoryDate = wtmodel.LaboratoryDate,
                    WorkerName     = wtmodel.WorkerName,
                    StationId      = wtmodel.StationId,
                };
                Chemical ch = new Chemical()
                {
                    Id        = wtmodel.Id,
                    Residue   = wtmodel.Residue,
                    Ph        = wtmodel.Ph,
                    Rigidity  = wtmodel.Rigidity,
                    Chlorides = wtmodel.Chlorides,
                    Sulphates = wtmodel.Sulphates,
                    Iron      = wtmodel.Iron,
                    Marhan    = wtmodel.Marhan,
                    Fluorine  = wtmodel.Fluorine,
                    Nitrates  = wtmodel.Nitrates
                };
                Organoleptic or = new Organoleptic()
                {
                    Id           = wtmodel.Id,
                    Scent20      = wtmodel.Scent20,
                    Scent60      = wtmodel.Scent60,
                    Flavor       = wtmodel.Flavor,
                    Chromaticity = wtmodel.Chromaticity,
                    Turbidity    = wtmodel.Turbidity,
                    Temperature  = wtmodel.Temperature
                };

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

                db.Entry(wt).State = EntityState.Modified;
                db.Entry(ch).State = EntityState.Modified;
                db.Entry(or).State = EntityState.Modified;
                var     k = db.WaterIntakes.OrderByDescending(a => a.Id).First();
                Station s = db.Stations.Find(wtmodel.StationId);
                if (wtmodel.Id == k.Id)
                {
                    s.Class = CheckingClass(ch, or);
                }
                db.Entry(s).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("WaterIntakes"));
            }

            WaterIntakeViewBag();
            return(View(wtmodel));
        }