public ActionResult Add_Student(Student st, Student_Courses sc) { if (st.Photo == null) { st.Photo = "user2.png"; } var exist = db.Students.Any(ww => ww.UserName == st.UserName); if (exist) { ViewBag.error = "This UserName Is Already Exist!!"; ViewBag.DeptList = new SelectList(db.Departments.ToList(), "Dept_Id", "DeptName", 1); ViewBag.courses = new SelectList(db.Courses.ToList(), "Course_Code", "Course_Name", 1); return(View()); } st.Admin_Id = 1; st.Type = "Student"; st.Visible = true; st.Attendence = 1; sc.Course_Code = st.Course; sc.Student_Code = st.Student_Code; db.Student_Courses.Add(sc); db.Students.Add(st); db.SaveChanges(); return(RedirectToAction("Students")); }
/// <summary> /// Check if student learn at course</summary> /// <param name="StudID">Student ID</param> /// <param name="CourseID">Course ID</param> /// <value>if student learn at specific course</value> private bool studentInCourse(string StudID, int CourseID) { Student_Courses ss = context.Student_Courses.FirstOrDefault(s => s.stud_Id == StudID && s.course_id == CourseID && s.Type == 1 && (s.final_grade == null || s.final_grade < 56)); if (ss != null) { return(true); } return(false); }
private void SignBtn_Click(object sender, EventArgs e) { //Check if necessary items selected if (lecturesListBox.Items.Count > 0 && lecturesListBox.SelectedIndex == -1 || practicesListBox.Items.Count > 0 && practicesListBox.SelectedIndex == -1 || labsListBox.Items.Count > 0 && labsListBox.SelectedIndex == -1) { MessageBox.Show("Unable to Sign. Select at least one Lecture, Practice, Lab (if available)", "Wrong selection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (lectureOverlapp || practiceOverlap || labOverlap) { MessageBox.Show("Overlapping courses!", "Wrong selection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult dialogResult = MessageBox.Show("Are you sure you want to sign to " + courseComboBox.Text.Trim() + "?", "Sign", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { using (Entities context = new Entities()) { //Delete previous if existed foreach (Lecture_Course c in selectedCourse) { Student_Courses course = context.Student_Courses.FirstOrDefault(x => x.course_id == c.Course_ID && x.stud_Id == Utility.User.ID); if (course != null) { context.Student_Courses.Remove(course); } } //Sign to new one foreach (Lecture_Course lc in choosen) { Student_Courses sc = new Student_Courses { stud_Id = Utility.User.ID, course_id = lc.Course_ID, grade_a = null, grade_b = null, grade_c = null, quiz1 = null, quiz2 = null, final_grade = null, Type = lc.Course_type, course_serial = lc.Course_Serial, Exam1_ID = null, Exam2_ID = null, Exam3_ID = null }; context.Student_Courses.Add(sc); } context.SaveChanges(); } MessageBox.Show("You signed to " + courseComboBox.Text.Trim() + "!"); clearAll(); } }
private void UnsignBtn_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you sure you want to unsign from " + courseComboBox.Text.Trim() + "?", "Unsign", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { using (Entities context = new Entities()) { foreach (Lecture_Course c in selectedCourse) { Debug.WriteLine(c.Course_ID); Student_Courses course = context.Student_Courses.FirstOrDefault(x => x.course_id == c.Course_ID && x.stud_Id == Utility.User.ID && c.Course_type == x.Type); context.Student_Courses.Remove(course); } context.SaveChanges(); } MessageBox.Show("You unsigned from " + courseComboBox.Text.Trim() + "!"); clearAll(); } }
private bool AddExamToStudents(string StudID, int ExamID) { context = new Entities(); double a = courseByExam(ExamID); Student_Courses ss = context.Student_Courses.FirstOrDefault(s => s.stud_Id == StudID && s.course_id == a && s.Type == 1); switch (returnDueIn(ExamID)) { case 1: if (ss.Exam1_ID == null) { ss.Exam1_ID = ExamID; cnt_Add++; context.SaveChanges(); return(true); } else { MessageBox.Show(ss.stud_Id + " already registered to exam"); return(false); } case 2: ss.Exam2_ID = ExamID; context.SaveChanges(); cnt_Add++; return(true); case 3: ss.Exam3_ID = ExamID; context.SaveChanges(); cnt_Add++; return(true); } return(false); }