// GET: PhenologicalStages/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhenologicalStage phenologicalStage = db.PhenologicalStages.Find(id);

            if (phenologicalStage == null)
            {
                return(HttpNotFound());
            }
            PhenologicalStageViewModel vm = new PhenologicalStageViewModel();

            vm.PhenologicalStageId = phenologicalStage.PhenologicalStageId;
            vm.SpecieId            = phenologicalStage.SpecieId;
            vm.StageId             = phenologicalStage.StageId;
            vm.MinDegree           = phenologicalStage.MinDegree;
            vm.MaxDegree           = phenologicalStage.MaxDegree;
            vm.RootDepth           = phenologicalStage.RootDepth;
            vm.HydricBalanceDepth  = phenologicalStage.HydricBalanceDepth;
            vm.Coefficient         = phenologicalStage.Coefficient;
            vm.DegreesDaysInterval = phenologicalStage.DegreesDaysInterval;
            vm.Stages  = this.LoadStages(phenologicalStage.StageId, phenologicalStage);
            vm.Species = this.LoadSpecies(phenologicalStage.SpecieId, phenologicalStage);
            return(View("~/Views/Agriculture/PhenologicalStages/Edit.cshtml", vm));
        }
        // GET: PhenologicalStages/Create
        public ActionResult Create()
        {
            PhenologicalStageViewModel vm = new PhenologicalStageViewModel();

            vm.Stages  = this.LoadStages();
            vm.Species = this.LoadSpecies();
            return(View("~/Views/Agriculture/PhenologicalStages/Create.cshtml", vm));
        }
        public ActionResult Create([Bind(Include = "PhenologicalStageId,StageId,SpecieId,MinDegree,MaxDegree,RootDepth,HydricBalanceDepth,Coefficient,DegreesDaysInterval")] PhenologicalStageViewModel phenologicalStageViewModel)
        {
            if (ModelState.IsValid)
            {
                PhenologicalStage phenologicalStage = new PhenologicalStage();
                phenologicalStage.SpecieId            = phenologicalStageViewModel.SpecieId;
                phenologicalStage.StageId             = phenologicalStageViewModel.StageId;
                phenologicalStage.MinDegree           = phenologicalStageViewModel.MinDegree;
                phenologicalStage.MaxDegree           = phenologicalStageViewModel.MaxDegree;
                phenologicalStage.RootDepth           = phenologicalStageViewModel.RootDepth;
                phenologicalStage.HydricBalanceDepth  = phenologicalStageViewModel.HydricBalanceDepth;
                phenologicalStage.Coefficient         = phenologicalStageViewModel.Coefficient;
                phenologicalStage.DegreesDaysInterval = phenologicalStageViewModel.DegreesDaysInterval;

                db.PhenologicalStages.Add(phenologicalStage);
                db.SaveChanges();
            }

            return(Redirect("/PhenologicalStages"));
        }
        public ActionResult Edit([Bind(Include = "PhenologicalStageId,SpecieId, StageId, MinDegree,MaxDegree,RootDepth,HydricBalanceDepth,Coefficient,DegreesDaysInterval")] PhenologicalStageViewModel phenologicalStageViewModel)
        {
            if (ModelState.IsValid)
            {
                PhenologicalStage phenologicalStage = db.PhenologicalStages.Find(phenologicalStageViewModel.PhenologicalStageId);
                if (phenologicalStage == null)
                {
                    return(HttpNotFound());
                }

                phenologicalStage.SpecieId            = phenologicalStageViewModel.SpecieId;
                phenologicalStage.StageId             = phenologicalStageViewModel.StageId;
                phenologicalStage.MinDegree           = phenologicalStageViewModel.MinDegree;
                phenologicalStage.MaxDegree           = phenologicalStageViewModel.MaxDegree;
                phenologicalStage.RootDepth           = phenologicalStageViewModel.RootDepth;
                phenologicalStage.HydricBalanceDepth  = phenologicalStageViewModel.HydricBalanceDepth;
                phenologicalStage.Coefficient         = phenologicalStageViewModel.Coefficient;
                phenologicalStage.DegreesDaysInterval = phenologicalStageViewModel.DegreesDaysInterval;

                db.Entry(phenologicalStage).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Redirect("/PhenologicalStages"));
        }