private WaterIntake WaterIntakeModelToWaterIntakeMap(WaterIntakeModel wtmodel) { WaterIntake wt = new WaterIntake() { Id = 100, LaboratoryId = wtmodel.LaboratoryId, IntakeDate = wtmodel.IntakeDate, LaboratoryDate = wtmodel.LaboratoryDate, WorkerName = wtmodel.WorkerName, StationId = wtmodel.StationId }; return(wt); }
private Organoleptic WaterIntakeModelToOrganoleptic(WaterIntakeModel wtmodel) { Organoleptic or = new Organoleptic() { Id = 100, Scent20 = wtmodel.Scent20, Scent60 = wtmodel.Scent60, Flavor = wtmodel.Flavor, Chromaticity = wtmodel.Chromaticity, Turbidity = wtmodel.Turbidity, Temperature = wtmodel.Temperature }; return(or); }
public ActionResult EditWaterIntake(int?id) { if (id == null) { return(HttpNotFound()); } WaterIntake wt = db.WaterIntakes.Find(id); if (wt == null) { return(HttpNotFound()); } Chemical ch = wt.Chemical; Organoleptic or = wt.Organoleptic; WaterIntakeModel wtmodel = new WaterIntakeModel() { Id = wt.Id, LaboratoryId = wt.LaboratoryId, IntakeDate = wt.IntakeDate, LaboratoryDate = wt.LaboratoryDate, WorkerName = wt.WorkerName, StationId = wt.StationId, Status = wt.Status, Residue = ch.Residue, Ph = ch.Ph, Rigidity = ch.Rigidity, Chlorides = ch.Chlorides, Sulphates = ch.Sulphates, Iron = ch.Iron, Marhan = ch.Marhan, Fluorine = ch.Fluorine, Nitrates = ch.Nitrates, Scent20 = or.Scent20, Scent60 = or.Scent60, Flavor = or.Flavor, Chromaticity = or.Chromaticity, Turbidity = or.Turbidity, Temperature = or.Temperature }; WaterIntakeViewBag(); return(View(wtmodel)); }
private Chemical WaterIntakeModelToChemical(WaterIntakeModel wtmodel) { Chemical ch = new Chemical() { Id = 100, 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 }; return(ch); }
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)); }
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)); } }