Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,ParentID,StudentID")] ParentAssignment parentAssignment)
        {
            if (id != parentAssignment.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(parentAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ParentAssignmentExists(parentAssignment.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParentID"]  = new SelectList(_context.Parents, "ParentID", "Fullname", parentAssignment.ParentID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "Fullname", parentAssignment.StudentID);
            return(View(parentAssignment));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,ParentID,StudentID")] ParentAssignment parentAssignment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(parentAssignment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ParentID"]  = new SelectList(_context.Parents, "ParentID", "Fullname", parentAssignment.ParentID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "Fullname", parentAssignment.StudentID);
            return(View(parentAssignment));
        }