コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Fullname,PhoneNumber")] Parent parent)
        {
            if (id != parent.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(parent);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ParentExists(parent.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(parent));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ClassName,TutorName")] Classroom classroom)
        {
            if (id != classroom.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(classroom);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClassroomExists(classroom.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(classroom));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(long id,
                                               [Bind("Id,FirstName,LastName,MatricNumber,Email,Age,Parent,Class")] EditStudentViewModel student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Parent parent = _context.Parent.Where(p => string.Compare(p.Fullname, student.Parent, true) == 0).FirstOrDefault();
                    if (parent == null)
                    {
                        return(View(student));
                    }

                    Classroom classroom = _context.Classroom.Where(c => string.Compare(c.ClassName, student.Class, true) == 0).FirstOrDefault();
                    if (classroom == null)
                    {
                        return(View(student));
                    }

                    var _student = _context.Student.Find(student.Id);
                    if (_student == null)
                    {
                        return(View(student));
                    }


                    _student.FirstName    = student.FirstName;
                    _student.LastName     = student.LastName;
                    _student.MatricNumber = student.MatricNumber;
                    _student.Email        = student.Email;
                    _student.Age          = student.Age;
                    _student.Parent       = parent;
                    _student.Class        = classroom;

                    _context.Update(_student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }