// zeigt Daten aus zwei Models an public ActionResult ViewModelDemo() { StudentFacultyViewModel vm = new StudentFacultyViewModel(); vm.AllStudents = RepositoryClass.GetStudents(); vm.AllFaculties = RepositoryClass.GetFaculty(); return(View(vm)); }
public IActionResult StudentFacultyInfos() { var optionsBuilder = new DbContextOptionsBuilder <AppDbContext>(); var unitOfWork = new UnitOfWork(new AppDbContext(optionsBuilder.Options)); var allYears = new List <int>(); for (int mark = 1; mark <= 6; mark++) { allYears.Add(mark); } var model = new StudentFacultyViewModel(); var allDepartments = new List <string>(); var allFaculties = new List <string>(); allDepartments.Add("Selectionner le Département"); allFaculties = unitOfWork.Faculties.GetFacultiesNames().ToList(); allFaculties.Insert(0, "Selectionner la faculté"); var partTimes = new List <string>(); partTimes.Add("SI"); partTimes.Add("NO"); var studentProfiles = new List <string>(); studentProfiles.Add("ETUDIANT STANDARD"); studentProfiles.Add("ETUDIANT NON STANDARD"); model.StudentProfiles = new SelectList(studentProfiles); model.PartTimes = new SelectList(partTimes); model.AllDepartments = new SelectList(allDepartments); model.AllFaculties = new SelectList(allFaculties); model.AllCurrentYears = new SelectList(allYears); return(View(model)); }
public IActionResult StudentFacultyInfos(StudentFacultyViewModel model, string button) { var optionsBuilder = new DbContextOptionsBuilder <AppDbContext>(); var unitOfWork = new UnitOfWork(new AppDbContext(optionsBuilder.Options)); var allYears = new List <int>(); for (int mark = 1; mark <= 6; mark++) { allYears.Add(mark); } var allDepartments = new List <string>(); var allFaculties = new List <string>(); allDepartments.Add("Selectionner le Département"); allFaculties = unitOfWork.Faculties.GetFacultiesNames().ToList(); allFaculties.Insert(0, "Selectionner la faculté"); var partTimes = new List <string>(); partTimes.Add("SI"); partTimes.Add("NO"); var studentProfiles = new List <string>(); studentProfiles.Add("ETUDIANT STANDARD"); studentProfiles.Add("ETUDIANT NON STANDARD"); model.StudentProfiles = new SelectList(studentProfiles); model.PartTimes = new SelectList(partTimes); model.AllDepartments = new SelectList(allDepartments); model.AllFaculties = new SelectList(allFaculties); model.AllCurrentYears = new SelectList(allYears); if (button == "first") { return(RedirectToAction("HighSchoolInfos")); } if (ModelState.IsValid) { var existStudent = unitOfWork.UserStudents.ExistStudentWithSerialNumber(model.SerialNumber); if (existStudent) { ViewBag.ErrorMessage = $"L'étudiant avec le matricule {model.SerialNumber} existe déjà dans la base de donnée"; return(View(model)); } DateTime enrollmentYear = DateTime.Now; string monthOfEnrollment = DateTime.Now.ToString("MM"); if (!(Int32.Parse(monthOfEnrollment) > 9 && Int32.Parse(monthOfEnrollment) < 12)) { enrollmentYear = enrollmentYear.AddYears(-1); } TempData["CurrentYear"] = model.CurrentYear; TempData["Department"] = model.Department; TempData["Faculty"] = model.Faculty; TempData["YearOfEnrolement"] = enrollmentYear; TempData["SerialNumber"] = model.SerialNumber; TempData["PartTime"] = model.PartTime; TempData["StudentProfile"] = model.StudentProfile; return(RedirectToAction("ConfirmStudentEnrollment")); } ViewBag.ErrorMessage = $"Impossible d'inscrire l'étudiant {TempData["FirstName"]?.ToString()} {TempData["LastName"]?.ToString()}"; return(View(model)); }