Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ModuleId,FarmId,PlantTypeId")] SmartPlants.Models.Module @module)
        {
            if (id != @module.ModuleId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(@module);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ModuleExists(@module.ModuleId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FarmId"]      = new SelectList(_context.Farms, "FarmId", "Name", @module.FarmId);
            ViewData["PlantTypeId"] = new SelectList(_context.PlantTypes, "PlantTypeId", "Name", @module.PlantTypeId);
            return(View(@module));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ModuleId,FarmId,PlantTypeId")] SmartPlants.Models.Module @module)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@module);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FarmId"]      = new SelectList(_context.Farms, "FarmId", "FarmId", @module.FarmId);
            ViewData["PlantTypeId"] = new SelectList(_context.PlantTypes, "PlantTypeId", "PlantTypeId", @module.PlantTypeId);
            return(View(@module));
        }