public ActionResult SaveEligibility(Student_Program studentProgram, string language) { ChangeLanguageFunction(language); var StuPrgInDb = _context.StudentPrograms.ToList().Where(p => p.ProgramId == studentProgram.ProgramId); var id = Request.Form[""]; foreach (var item in StuPrgInDb) { id = Request.Form[item.StudentId.ToString()]; if ("true" == id) { item.IsEligible = true; } else { item.IsEligible = false; } } _context.SaveChanges(); return(RedirectToAction("EligibleList", "EnglishProgram", new { id = studentProgram.ProgramId })); }
public ActionResult SaveFromAdmin(Student_Program studentProgram, string language) { ChangingLanguageFunction(language); if (language.Equals("ar")) { if (!ModelState.IsValid) { var StudentPrograms = new Student_Program(studentProgram.ProgramId); return(View("~/Views/ArabicViews/ArabicProgram/RegistrationFormAdmin.cshtml", StudentPrograms)); } } else { if (!ModelState.IsValid) { var StudentPrograms = new Student_Program(studentProgram.ProgramId); return(View("~/Views/EnglishViews/EnglishProgram/RegistrationFormAdmin.cshtml", StudentPrograms)); } } _context.StudentPrograms.Add(studentProgram); // Searches in the database to find if the specified student exists in the database or not, returns boolean var StuProg = _context.StudentPrograms.Where(p => p.ProgramId == studentProgram.ProgramId).Where(s => s.StudentId == studentProgram.StudentId).Any(); try { _context.SaveChanges(); // Sends the Successfull message of Adding Student to the Program to another action using the TempData TempData["AddingStudentToProgramByAdminSuccsessMessage"] = 1; } catch (DbUpdateException) { //MessageBox.Show(StudentActivity.Resources.Language.Added_student_already_registerd_in_program + StudentActivity.Resources.Language.Student_not_registerd_in_website, "Existence Error"); // Checks If student exists in the database if (StuProg == true) { // Sends the error message of Adding Student to the Program who is already registered in the program to another action using the TempData TempData["AddingStudentToProgramByAdminRegisterdErrorMessage"] = 1; return(RedirectToAction("EligibleList", "Program", new { id = studentProgram.ProgramId })); } if (StuProg == false) { // Sends the error message of Adding Student to the Program who does not exist in the database to another action using the TempData TempData["AddingStudentToProgramByAdminExistingErrorMessage"] = 1; return(RedirectToAction("EligibleList", "Program", new { id = studentProgram.ProgramId })); } } return(RedirectToAction("EligibleList", "Program", new { id = studentProgram.ProgramId })); }