public ActionResult DeleteCrop(int id, CropDataViewModel cropDataViewModel) //Deletes the requested Product (identified by the Product ID)
        {
            try
            {
                Crop myCrop = _cropService.GetCrop(id);
                _cropService.DeleteCrop(myCrop);

                CropHarvest myCropHarvest = _cropService.GetCropHarvest(id);
                _cropService.DeleteCropHarvest(myCropHarvest);

                CropRequirements myCropRequirements = _cropService.GetCropRequirements(id);
                _cropService.DeleteCropRequirements(myCropRequirements);
            }
            catch (Exception ex)
            {
                // Might be worth looking at redirection to an error page
                ViewBag.Exception = ex;
                return(View());
            }

            return(RedirectToAction("Crops", new { controller = "Crop" }));
        }
        public ActionResult EditCrop(int id, CropDataViewModel cropDataViewModel, Crop crop, CropHarvest cropHarvest, CropRequirements cropRequirements)
        {
            try
            {
                Crop myCrop = new Crop
                {
                    cropId   = cropDataViewModel.CropId,
                    cropName = cropDataViewModel.CropName,
                    cropSize = cropDataViewModel.SpaceRequired
                };

                CropHarvest myCroph = new CropHarvest
                {
                    cropId          = cropDataViewModel.CropId,
                    earliestHarvest = cropDataViewModel.EarlyHarvest,
                    latestHarvest   = cropDataViewModel.LateHarvest,
                    earliestPlant   = cropDataViewModel.EarlyPlanting,
                    latestPlant     = cropDataViewModel.LatePlanting,
                    growthTime      = cropDataViewModel.growthTime
                };

                CropRequirements myCropr = new CropRequirements
                {
                    cropId           = cropRequirements.cropId,
                    birdNetting      = cropRequirements.birdNetting,
                    slugPellets      = cropRequirements.slugPellets,
                    Feed             = cropRequirements.Feed,
                    wateringInterval = cropRequirements.wateringInterval
                };

                _cropService.editCrop(myCrop, myCroph, myCropr);

                return(RedirectToAction("Crops", new { controller = "Crop" }));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult AddCrop(Crop crop, CropHarvest croph, CropRequirements cropr, CropDataViewModel cropDataViewModel)
        {
            try
            {
                Crop mycrop = new Crop
                {
                    cropId   = cropDataViewModel.CropId,
                    cropName = cropDataViewModel.CropName,
                    cropSize = cropDataViewModel.SpaceRequired
                };

                _cropService.addCrop(mycrop);

                CropHarvest myCroph = new CropHarvest
                {
                    cropId          = cropDataViewModel.CropId,
                    earliestHarvest = cropDataViewModel.EarlyHarvest,
                    latestHarvest   = cropDataViewModel.LateHarvest,
                    earliestPlant   = cropDataViewModel.EarlyPlanting,
                    latestPlant     = cropDataViewModel.LatePlanting,
                    growthTime      = cropDataViewModel.growthTime,
                };

                _cropService.addCropHarvest(myCroph);

                _cropService.addCropRequirements(cropr);

                return(RedirectToAction("Crops", new { controller = "Crop" }));
            }
            catch (Exception ex)
            {
                // Might be worth looking at redirection to an error page
                ViewBag.Exception = ex;
                return(View());
            }
        }
示例#4
0
        public void editCrop(Crop crop, CropHarvest cropHarvest, CropRequirements cropRequirements)
        {
            Crop myCrop = GetCrop(crop.cropId);

            myCrop.cropName = crop.cropName;
            myCrop.cropSize = crop.cropSize;

            CropHarvest myCroph = GetCropHarvest(cropHarvest.cropId);

            myCroph.earliestHarvest = cropHarvest.earliestHarvest;
            myCroph.latestHarvest   = cropHarvest.latestHarvest;
            myCroph.earliestPlant   = cropHarvest.earliestPlant;
            myCroph.latestPlant     = cropHarvest.latestPlant;
            myCroph.growthTime      = cropHarvest.growthTime;

            CropRequirements myCropr = GetCropRequirements(cropRequirements.cropId);

            myCropr.birdNetting      = cropRequirements.birdNetting;
            myCropr.slugPellets      = cropRequirements.slugPellets;
            myCropr.Feed             = cropRequirements.Feed;
            myCropr.wateringInterval = cropRequirements.wateringInterval;

            _context.SaveChanges();
        }
示例#5
0
 public void DeleteCropHarvest(CropHarvest cropHarvest)
 {
     _cropDAO.DeleteCropHarvest(cropHarvest);
 }
示例#6
0
 public void editCrop(Crop crop, CropHarvest cropHarvest, CropRequirements cropRequirements)
 {
     _cropDAO.editCrop(crop, cropHarvest, cropRequirements);
 }
示例#7
0
 public void addCropHarvest(CropHarvest crop)
 {
     _cropDAO.addCropHarvest(crop);
 }
示例#8
0
 public void DeleteCropHarvest(CropHarvest cropHarvest)
 {
     _context.CropHarvest.Remove(cropHarvest);
     _context.SaveChanges();
 }
示例#9
0
 public void addCropHarvest(CropHarvest cropHarvest)
 {
     _context.CropHarvest.Add(cropHarvest);
     _context.SaveChanges();
 }