コード例 #1
0
        public IActionResult Create()
        {
            var courses   = this.courseServices.GetAll <CourseDropDownViewModel>();
            var viewModel = new StudentsCreateViewModel();

            viewModel.Courses = courses;
            return(this.View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Create(StudentsCreateViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                inputModel.Courses = this.courseServices.GetAll <CourseDropDownViewModel>();
                return(this.View(inputModel));
            }

            var studentId = await this.studentsServices.CreateAsync(inputModel.FirstName, inputModel.LastName, inputModel.BirthDate, inputModel.CourseId);

            await this.courseServices.AddStudetToCourse(inputModel.CourseId, studentId);

            return(this.RedirectToAction("Details", "Courses", new { id = inputModel.CourseId }));
        }