public ActionResult Edit([Bind(Include = "HorizonId,Name,Order,HorizonLayer,HorizonLayerDepth,Sand,Limo,Clay,OrganicMatter,NitrogenAnalysis,BulkDensitySoil, SoilId")] HorizonViewModel horizonViewModel) { if (ModelState.IsValid) { Horizon updatedHorizon = db.Horizons.Find(horizonViewModel.HorizonId); if (updatedHorizon == null) { return(HttpNotFound()); } updatedHorizon.BulkDensitySoil = horizonViewModel.BulkDensitySoil; updatedHorizon.Clay = horizonViewModel.Clay; updatedHorizon.HorizonLayer = horizonViewModel.HorizonLayer; updatedHorizon.HorizonLayerDepth = horizonViewModel.HorizonLayerDepth; updatedHorizon.Limo = horizonViewModel.Limo; updatedHorizon.Name = horizonViewModel.Name; updatedHorizon.NitrogenAnalysis = horizonViewModel.NitrogenAnalysis; updatedHorizon.Order = horizonViewModel.Order; updatedHorizon.OrganicMatter = horizonViewModel.OrganicMatter; updatedHorizon.Sand = horizonViewModel.Sand; updatedHorizon.SoilId = horizonViewModel.SoilId; db.Entry(updatedHorizon).State = EntityState.Modified; db.SaveChanges(); } return(Redirect("/Horizons")); //var lHorizonList = db.Horizons.Include(s => s.Soil); //return View("~/Views/Agriculture/Horizons/Index.cshtml", lHorizonList.ToList()); }
// GET: Horizons/Create public ActionResult Create() { HorizonViewModel vm = new HorizonViewModel(); vm.Soils = this.LoadSoils(); return(View("~/Views/Agriculture/Horizons/Create.cshtml", vm)); }
// GET: Horizons/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Horizon horizon = db.Horizons.Find(id); if (horizon == null) { return(HttpNotFound()); } HorizonViewModel vm = new HorizonViewModel(horizon); return(View("~/Views/Agriculture/Horizons/Details.cshtml", vm)); }
public ActionResult Create([Bind(Include = "HorizonId,Name,Order,HorizonLayer,HorizonLayerDepth,Sand,Limo,Clay,OrganicMatter,NitrogenAnalysis,BulkDensitySoil, SoilId")] HorizonViewModel h) { if (ModelState.IsValid) { Horizon lHorizon = new Horizon(); lHorizon.BulkDensitySoil = h.BulkDensitySoil; lHorizon.Clay = h.Clay; lHorizon.HorizonLayer = h.HorizonLayer; lHorizon.HorizonLayerDepth = h.HorizonLayerDepth; lHorizon.Limo = h.Limo; lHorizon.Name = h.Name; lHorizon.NitrogenAnalysis = h.NitrogenAnalysis; lHorizon.Order = h.Order; lHorizon.OrganicMatter = h.OrganicMatter; lHorizon.Sand = h.Sand; lHorizon.SoilId = h.SoilId; db.Horizons.Add(lHorizon); db.SaveChanges(); } return(Redirect("/Horizons")); //var lHorizonList = db.Horizons.Include(s => s.Soil); //return View("~/Views/Agriculture/Horizons/Index.cshtml", lHorizonList.ToList()); }
public void HorizonViewModelInitialize() { // Arrangements var topHorizon = new int[, ] { { 1, 2 }, { 2, 3 } }; var _applicationCommands = new ApplicationCommands(); _mockHorizonDataService.Setup(s => s.GetTopHorizonDepthInFeet()).Returns(topHorizon); _mockVolumeCalculationService.Setup(s => s.CalculateOilAndGasVolumeFromTopHorizonInCubicMeter(topHorizon)).Returns(12.0); // Actions var horizonViewModel = new HorizonViewModel(_applicationCommands, _mockHorizonDataService.Object, _mockVolumeCalculationService.Object); // Assertions Assert.IsNotNull(horizonViewModel); Assert.IsNotNull(horizonViewModel.ShowVolumeCommand); _mockHorizonDataService.Verify(c => c.GetTopHorizonDepthInFeet(), Times.Once()); _mockVolumeCalculationService.Verify(c => c.CalculateOilAndGasVolumeFromTopHorizonInCubicMeter(topHorizon), Times.Once()); Assert.AreEqual(12.0, horizonViewModel.VolumeOfOilAndGasInCubicMeter); }