public IActionResult Create() { var courses = this.courseServices.GetAll <CourseDropDownViewModel>(); var viewModel = new StudentsCreateViewModel(); viewModel.Courses = courses; return(this.View(viewModel)); }
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 })); }