/// <summary>
        /// Update an existing Crop, if not exists return null
        /// </summary>
        /// <param name="pName"></param>
        /// <param name="pSpecieCycle"></param>
        /// <param name="pRegion"></param>
        /// <param name="pCropCoefficient"></param>
        /// <param name="pStageList"></param>
        /// <param name="pPhenologicalStageList"></param>
        /// <param name="pDensity"></param>
        /// <param name="pMaxEvapotranspirationToIrrigate"></param>
        /// <param name="pMinEvapotranspirationToIrrigate"></param>
        /// <returns></returns>
        public Crop UpdateCrop(String pName, Specie pSpecie, Region pRegion,
                               CropCoefficient pCropCoefficient,
                               List <PhenologicalStage> pPhenologicalStageList,
                               Double pDensity, Double pMaxEvapotranspirationToIrrigate,
                               Double pMinEvapotranspirationToIrrigate)
        {
            Crop lReturn = null;
            Crop lCrop   = new Crop(0,
                                    pName,
                                    pRegion.RegionId,
                                    pSpecie.SpecieId,
                                    pCropCoefficient.CropCoefficientId,
                                    pPhenologicalStageList,
                                    pDensity,
                                    pMaxEvapotranspirationToIrrigate,
                                    pMinEvapotranspirationToIrrigate);

            lReturn = this.ExistCrop(lCrop);
            if (lReturn != null)
            {
                lReturn.Name              = pName;
                lReturn.RegionId          = pRegion.RegionId;
                lReturn.SpecieId          = pSpecie.SpecieId;
                lReturn.CropCoefficientId = pCropCoefficient.CropCoefficientId;
                lReturn.UpdatePhenologicalStageList(pPhenologicalStageList);
                lReturn.Density = pDensity;
                lReturn.MaxEvapotranspirationToIrrigate = pMaxEvapotranspirationToIrrigate;
                lReturn.MinEvapotranspirationToIrrigate = pMinEvapotranspirationToIrrigate;
            }
            return(lReturn);
        }
        public ActionResult DeleteConfirmed(long id)
        {
            CropCoefficient cropCoefficient = db.CropCoefficients.Find(id);

            db.CropCoefficients.Remove(cropCoefficient);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "CropCoefficientId")] CropCoefficient cropCoefficient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cropCoefficient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cropCoefficient));
 }
        public ActionResult Create([Bind(Include = "CropCoefficientId")] CropCoefficient cropCoefficient)
        {
            if (ModelState.IsValid)
            {
                db.CropCoefficients.Add(cropCoefficient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cropCoefficient));
        }
        // GET: CropCoefficients/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CropCoefficient cropCoefficient = db.CropCoefficients.Find(id);

            if (cropCoefficient == null)
            {
                return(HttpNotFound());
            }
            return(View(cropCoefficient));
        }
Example #6
0
        public void cropCoefficientTestByList()
        {
            int    lDay1 = 1;
            int    lDay2 = 2;
            int    lDay3 = 3;
            double lKC1  = 3.5;
            double lKC2  = 3.7;
            double lKC3  = 4;

            CropCoefficient lCropCoefficient = new CropCoefficient();
            Specie          lSpecie          = new Specie(0, "Maiz", "Maiz", 1, 30, 40, Utils.SpecieType.Grains);

            lCropCoefficient.AddOrUpdateKCforDayAfterSowing(lSpecie.SpecieId, lDay1, lKC1);
            lCropCoefficient.AddOrUpdateKCforDayAfterSowing(lSpecie.SpecieId, lDay2, lKC2);
            lCropCoefficient.AddOrUpdateKCforDayAfterSowing(lSpecie.SpecieId, lDay3, lKC3);

            Assert.IsTrue(lCropCoefficient.GetCropCoefficient(1) == lKC1);
            Assert.IsTrue(lCropCoefficient.GetCropCoefficient(2) == lKC2);
            Assert.IsTrue(lCropCoefficient.GetCropCoefficient(3) == lKC3);
        }