示例#1
0
        public ActionResult Add(StudentViewModel studentModel)
        {
            StudentsModel studentsModel = new StudentsModel(new StudentsService(new StudentsRepository(new StudentsContext())));

            var createdStudent = studentsModel.AddStudent(studentModel);

            return(View("StudentDetails", createdStudent));
        }
示例#2
0
        public ActionResult AddStudentAction()
        {
            string Name  = Request.Form["textName"];
            string Score = Request.Form["txtScore"];

            if ((Name == null) || (Name.Trim() == ""))
            {
                ViewData["ERROR"] = "Please provide a name for the student to add";
                return(View("../Shared/Error"));
            }

            if (Name.Length < 6)
            {
                ViewData["ERROR"]
                    = "The student's name should not be less than 6 characters.";
                return(View("../Shared/Error"));
            }


            int intScore;

            if (!Int32.TryParse(Score, out intScore))
            {
                ViewData["ERROR"]
                    = "Please provide a valid score to the student to add.";
                return(View("../Shared/Error"));
            }


            if ((intScore < 60) || (intScore > 100))
            {
                ViewData["ERROR"]
                    = "We only accept students with scores between 60 and 100.";
                return(View("../Shared/Error"));
            }

            StudentsModel theModel = GetStudentModelFromSession();

            theModel.AddStudent(Name, intScore);

            ViewData["Students"] = theModel.GetStudents();
            return(View("StudentList"));
        }