Exemplo n.º 1
0
        public IActionResult Index()
        {
            List <Teacher> teachers = new List <Teacher>()
            {
                new Teacher()
                {
                    Name = "Alex", Class = "English"
                },
                new Teacher()
                {
                    Name = "Don", Class = "Math"
                },
                new Teacher()
                {
                    Name = "Peter", Class = "Science"
                },
                new Teacher()
                {
                    Name = "Paul", Class = "History"
                }
            };

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Teachers = teachers
            };

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public IActionResult Student(StudentTeacherViewModel model)
        //받고 싶은 데이터만 받는 방법: Bind Attribute 사용
        //public IActionResult Student([Bind("Name, Age")] Student model)
        //public IActionResult Student(Student model)
        {
            //유효성 검사
            if (ModelState.IsValid)
            {
                //true 리턴시, model 데이터를 Student 테이블에 저장
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();

                //입력 Data 초기화
                ModelState.Clear();
            }
            else
            {
                //TagHelper를 이용한 에러내용 출력
            }

            var students = _studentRepository.GetAllStudent();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public IActionResult Student(StudentTeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                //  model data 를 Student Table 에 저장
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();

                ModelState.Clear();
            }
            else
            {
                // 에러 메세지
            }

            var students = _studentRepository.GetALLStudents();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 4
0
        public IActionResult Student([Bind("Name, Age")] StudentModel model)
        {
            var viewModel = new StudentTeacherViewModel();

            viewModel.Student  = model;
            viewModel.Teachers = teachers;

            // 유효성 검사 통과 여부 ( T : Pass, F : fail )
            if (ModelState.IsValid)
            {
                // model 데이터를 Student 테이블에 저장
                _studentRepository.AddStudent(model);
                _studentRepository.Save();

                // Clear Input Data
                ModelState.Clear();
            }
            else
            {
                // 에러 메시지
            }

            var students = _studentRepository.GetAllStudents();

            viewModel.Student  = new StudentModel();
            viewModel.Students = students;

            return(View(viewModel));
        }
        /*[ValidateAntiForgeryToken] */ // 유저가 서버로 폼 정보를 보낼 때 이 정보가 유저에게 제공된 폼 정보가 맞는지 토큰 비교, 크로스 사이트 스크립팅 예방책 https://docs.microsoft.com/ko-kr/aspnet/core/security/anti-request-forgery?view=aspnetcore-2.1
        public IActionResult Student(StudentTeacherViewModel model)
        {
            //유효성 검사
            if (ModelState.IsValid)
            {
                //model 데이터 저장 로직
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();

                ModelState.Clear();
            }
            else
            {
                //에러 로직
            }

            var students  = _studentRepository.GetAllStudents();
            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 6
0
        // GET: /<controller>/
        public IActionResult Student()
        {
            List <Teacher> teachers = new List <Teacher>()
            {
                new Teacher()
                {
                    Name = "세종대왕", Class = "한글"
                },
                new Teacher()
                {
                    Name = "이순신", Class = "해상전략"
                },
                new Teacher()
                {
                    Name = "제갈량", Class = "지략"
                },
                new Teacher()
                {
                    Name = "을지문덕", Class = "지상전략"
                }
            };

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Teachers = teachers
            };

            return(View(viewModel));
        }
Exemplo n.º 7
0
        public IActionResult Student(StudentTeacherViewModel model)
        {
            // Check valid of model values
            if (ModelState.IsValid)
            {
                // Store model data into Student table
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();

                ModelState.Clear();
            }
            else
            {
                // If model values are not valid, display Error
            }

            var students = _studentRepository.GetAllStudents();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 8
0
        public IActionResult Student(StudentTeacherViewModel model)
        {
            // model에 있는 유효성 검사 확인
            if (ModelState.IsValid)
            {
                // model 데이터를 Student table에 저장
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();
                // input value 삭제
                ModelState.Clear();
            }
            else
            {
                // error
            }
            var students = _studentRepository.GetAllStudents();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };


            return(View(viewModel));
        }
Exemplo n.º 9
0
        public IActionResult Student(StudentTeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Store model data to Student table
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();

                ModelState.Clear();
            }
            else
            {
                // Show Error
            }

            var students = _studentRepository.GetAllStudents();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 10
0
        public ActionResult Index()
        {
            var vm = new StudentTeacherViewModel();

            vm.Students = GetStudents();
            vm.Teachers = GetTeachers();

            return(View(vm));
        }
        public ActionResult Details(int id)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home", null));
            }
            StudentTeacherViewModel StudentTeacher = StudentTeacherService.GetByID(id);

            return(View(StudentTeacher));
        }
Exemplo n.º 12
0
        public IActionResult Index()
        {
            var teachers  = _repository.GetAllTeachers();
            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Teachers = teachers
            };

            return(View(viewModel));
        }
Exemplo n.º 13
0
        // GET: /<controller>/
        public IActionResult Student()
        {
            var students = _studentRepository.GetAllStudents();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 14
0
        public IActionResult Student(StudentTeacherViewModel model)
        {
            if (ModelState.IsValid) //유효성 검사
            {
                //Model 데이터를 Student 테이블에 저장
            }
            else
            {
                //에러를 보여준다.
            }

            return(View());
        }
Exemplo n.º 15
0
        public IActionResult Student()
        {
            var students = _studentRepository.GetAllStudent();

            //StudentTeacherViewModel 인스턴스화
            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            //F12: 상세보기
            //return View();
            return(View(viewModel));
        }
        [ValidateAntiForgeryToken] //요청위조방지 유저가보낸게맞는지 확인함
        public IActionResult Student(StudentTeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                //model 대이터를 student table에 저장
                _Srepository.AddStudent(model.Student);
                _Srepository.Save();

                ModelState.Clear();
            }
            else
            {
            }

            var students = _Srepository.GetAllStudents();

            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };

            return(View(viewModel));
        }
Exemplo n.º 17
0
        public IActionResult Student(StudentTeacherViewModel model) // student model
        {
            // validate
            if (ModelState.IsValid)
            {
                // store data
                _studentRepository.AddStudent(model.Student);
                _studentRepository.Save();
                ModelState.Clear(); // delete input values
            }
            else
            {
                // error
            }
            var students  = _studentRepository.GetAllStudents();
            var viewModel = new StudentTeacherViewModel()
            {
                Student  = new Student(),
                Students = students
            };


            return(View(viewModel));
        }