Beispiel #1
0
        public ActionResult AddCropPrice(PriceViewModel model)
        {
            if (ModelState.IsValid)
            {
                CropPrice cropPrice = new CropPrice
                {
                    MeasurementId = model.MeasurementId,
                    UnitPrice     = model.UnitPrice,
                    DateCreated   = DateTime.Now
                };

                cropPrice = CropPriceService.Create(cropPrice);

                if (cropPrice != null)
                {
                    FarmCrop updateFarmCrop = FarmCropService.GetById(model.FarmCropId);
                    updateFarmCrop.CropPriceId = cropPrice?.Id;

                    FarmCropService.Update(updateFarmCrop);
                }
                return(RedirectToAction("Index", "Crop"));
            }
            model.MeasurementDropDown = base.GetMeasurement(model.MeasurementId);
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Add(FarmCropViewModel model)
        {
            //SaveCrop(model.FarmId, model.CropId);

            if (ModelState.IsValid)
            {
                if (model.Id > 0)
                {
                    FarmCrop farmCropToUpdate = FarmCropService.GetById(model.Id);
                    farmCropToUpdate.Hectarage       = model.Hectarage;
                    farmCropToUpdate.YieldPerHectar  = model.YieldPerHectar;
                    farmCropToUpdate.CropVarietyNote = model.CropVarietyNote;
                    farmCropToUpdate.IsActive        = true;

                    FarmCropService.Update(farmCropToUpdate);

                    return(RedirectToAction("Index"));
                }

                var farmCrop = new FarmCrop
                {
                    FarmId          = model.FarmId,
                    CropVarietyId   = model.CropVarietyId,
                    Hectarage       = model.Hectarage,
                    YieldPerHectar  = model.YieldPerHectar,
                    CropVarietyNote = model.CropVarietyNote,
                    IsActive        = true
                };
                FarmCropService.Create(farmCrop);

                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        // GET: Crop/Edit/5
        public PartialViewResult EditCrop(int FarmCropId)
        {
            FarmCrop farmCrop = FarmCropService.GetById(FarmCropId);

            FarmCropViewModel model = new FarmCropViewModel
            {
                Id                  = farmCrop.Id,
                CropId              = farmCrop.CropVariety.Crop.Id,
                CropVarietyId       = farmCrop.CropVariety.Crop.Id,
                CropTypeId          = (int)farmCrop.CropVariety.Crop.CropTypeId,
                CropDropDown        = GetCrop(farmCrop.CropVariety.Crop.Id),
                CropVarietyDropDown = GetCropVariety(farmCrop.CropVarietyId),
                CropTypeDropDown    = GetCropType(farmCrop.CropVariety.Crop.CropTypeId)
            };

            return(PartialView("_AddCropToFarmDialog", model));
        }
Beispiel #4
0
        public ActionResult PlantCrop(PlantingViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id > 0)
                {
                    Planting existingplanting = PlantingService.GetById(model.Id);

                    existingplanting.DatePlanted         = model.DatePlanted;
                    existingplanting.ExpectedHarvestDate = model.DatePlanted.AddMonths(model.MonthToGrowId);

                    PlantingService.Update(existingplanting);

                    return(RedirectToAction("Index", "Crop"));
                }

                Planting planting = new Planting
                {
                    DatePlanted         = model.DatePlanted,
                    ExpectedHarvestDate = model.DatePlanted.AddMonths(model.MonthToGrowId),
                    FarmCropId          = model.Id
                };

                planting = PlantingService.Create(planting);

                if (planting != null)
                {
                    FarmCrop updateFarmCrop = FarmCropService.GetById(model.FarmCropId);
                    updateFarmCrop.PlantingId = planting?.Id;

                    FarmCropService.Update(updateFarmCrop);
                }
                return(RedirectToAction("Index", "Crop"));
            }
            return(RedirectToAction("Index", "Crop"));
        }