コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Fullname,PhoneNumber")] Parent parent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(parent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(parent));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,ClassName,TutorName")] Classroom classroom)
        {
            if (ModelState.IsValid)
            {
                _context.Add(classroom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(classroom));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,MatricNumber,Email,Age,Parent,Class")] AddStudentViewModel _student)
        {
            if (ModelState.IsValid)
            {
                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));
                }

                Student student = new Student()
                {
                    FirstName    = _student.FirstName,
                    LastName     = _student.LastName,
                    MatricNumber = _student.MatricNumber,
                    Email        = _student.Email,
                    Age          = _student.Age,
                    Parent       = parent,
                    Class        = classroom,
                };


                _context.Add(student);
                await _context.SaveChangesAsync();

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