Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,GradeId")] Student student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GradeId"] = new SelectList(_context.Set <Grade>(), "Id", "Id", student.GradeId);
            return(View(student));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Grade grade)
        {
            if (ModelState.IsValid)
            {
                _context.Add(grade);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(grade));
        }