Ejemplo n.º 1
0
        // GET: Planting/Details/5
        public ActionResult Details(int Id)
        {
            PlantingViewModel model = new PlantingViewModel
            {
                PlantingDetail = _plantingService.GetById(Id)
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        // GET: Planting/Create
        public ActionResult PlantCrop(int?farmCropId)
        {
            var model = new PlantingViewModel
            {
                FarmCropId            = farmCropId.Value,
                HarvestPeriodDropDown = GetCropDueMonths(null)
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult PlantCrop(PlantingViewModel model)
        {
            if (ModelState.IsValid)
            {
                var planting = new Planting
                {
                    DatePlanted         = model.DatePlanted,
                    ExpectedHarvestDate = model.DatePlanted.AddMonths(model.MonthToGrowId)
                };

                _plantingService.Create(planting);

                return(RedirectToAction("Index", "FarmCrop"));
            }
            return(RedirectToAction("Index", "FarmCrop"));
        }
Ejemplo n.º 4
0
        public ActionResult PlantCrop(int?farmCropId)
        {
            PlantingViewModel model = null;

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Planting, PlantingViewModel>();
            });

            IMapper iMapper = config.CreateMapper();

            model                       = iMapper.Map <Planting, PlantingViewModel>(new Planting {
            });
            model.FarmCropId            = (int)farmCropId;
            model.HarvestPeriodDropDown = GetCropDueMonth(null);

            return(PartialView("_AddCropPlantingDialog", model));
        }
Ejemplo n.º 5
0
        public ActionResult UdatePlanting(int?id)
        {
            PlantingViewModel model = null;

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Planting, PlantingViewModel>();
            });

            IMapper iMapper = config.CreateMapper();

            Planting editPlanting = PlantingService.GetById(id);

            model = iMapper.Map <Planting, PlantingViewModel>(editPlanting);

            model.MonthToGrowId         = editPlanting.ExpectedHarvestDate.Month - editPlanting.DatePlanted.Month;
            model.HarvestPeriodDropDown = GetCropDueMonth(model.MonthToGrowId);
            return(PartialView("_AddCropPlantingDialog", model));
        }
Ejemplo n.º 6
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"));
        }