public async Task <IActionResult> CreateStudent() { var user = await _userManager.GetUserAsync(User); var isAdmin = await IsAdmin(); var schools = _schoolsServices.GetAllByUserId <SchoolViewModel>(user?.UniqueGradebookId, isAdmin); var inputModel = new StudentCreateInputModel { Schools = schools.Select(s => new SelectListItem(s.Name, s.Id.ToString())).ToList(), Classes = SetClasses(schools).ToList() }; return(View(inputModel)); }
public async Task <IActionResult> CreateStudent(StudentCreateInputModel inputModel) { if (!ModelState.IsValid || inputModel.Student.SchoolId.IsNullOrEmpty() || inputModel.Student.ClassId.IsNullOrEmpty()) { //ToDo: in case of null school/class, return appropriate message or add model validation? return(View(inputModel)); } try { var confirmViewModel = await _studentsService.CreateStudent <ConfirmCreatedViewModel>(inputModel.Student); return(RedirectToAction(nameof(ConfirmCreated), confirmViewModel)); } catch (Exception e) { _logger.LogError(e, $"An exception occured during new student record creation. Ex: {e.Message}"); return(RedirectToAction("Error", "Home")); } }
public async Task <IActionResult> Create(StudentCreateInputModel model) { if (this.ModelState.IsValid) { StudentServiceModel serviceModel = model.To <StudentServiceModel>(); bool result = await this.studentService.CreateStudentAsync(serviceModel); if (result) { return(this.RedirectToAction("All")); } } var classes = await this.classService.GetClassesDropdownAsync(); this.ViewBag.ClassesNames = classes; return(this.View(model)); }