예제 #1
0
        public async Task <IActionResult> EditPlant(EditGardenPlantViewModel viewmodel)
        {
            var PlantGarden = viewmodel.PlantGarden;
            var GardenBed   = await _context.GardenBeds.FindAsync(viewmodel.GardenBedId);

            var Plant = await _context.Plants.FindAsync(viewmodel.PlantGarden.PlantId);

            PlantGarden.GardenBed = GardenBed;
            PlantGarden.Plant     = Plant;

            ModelState.Remove("PlantGarden.PlantList");
            ModelState.Remove("PlantGarden.Plants");



            //viewmodel.PlantGarden = new PlantGarden
            //{
            //    Plant = await _context.Plants.FindAsync(viewmodel.PlantId),
            //    rowNumber = viewmodel.PlantGarden.rowNumber,
            //    plantCount = viewmodel.PlantGarden.plantCount,
            //    GardenBedId = viewmodel.GardenBedId,
            //    PlantId = viewmodel.PlantId,
            //    PlantGardenId = viewmodel.PlantGarden.PlantGardenId
            //};

            if (ModelState.IsValid)
            {
                _context.Update(PlantGarden);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "GardenBeds", new { id = viewmodel.GardenBedId }));
            }
            return(NotFound());
        }
예제 #2
0
        public async Task <IActionResult> EditPlant(int?id)
        {
            var currUser = await GetCurrentUserAsync();


            EditGardenPlantViewModel viewmodel = new EditGardenPlantViewModel
            {
                PlantList   = await _context.Plants.Select(p => new SelectListItem(p.PlantName, p.PlantId.ToString())).ToListAsync(),
                PlantGarden = await _context.PlantGardens.FindAsync(id)
            };

            return(View(viewmodel));
        }