protected void lb_studdelete_Click(object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; var id = int.Parse(lb.CommandArgument); var courseToRemove = cc.CourseByID(id); var gc = new GradesControl(); var gradesToRemove = gc.GetAllGrades().ToList().Where(x => x.CourseID == courseToRemove.Id); foreach (var grade in gradesToRemove) { gc.RemoveGrade(grade); } var ac = new AttendanceControl(); var attendanceToRemove = ac.GetAllAttendance().ToList().Where(a => a.CourseID == courseToRemove.Id); foreach (var attendance in attendanceToRemove) { ac.RemoveAttendance(attendance); } cc.RemoveCourse(courseToRemove); Response.Redirect($"Course"); }
protected void btn_addCourse_Click(object sender, EventArgs e) { var grade = new Grades(); string param = Request.QueryString["studentID"]; if (ddl_studCourse.SelectedValue != "0") { var studID = int.Parse(param); grade.Grade = ddl_studGrade.SelectedValue; grade.Completed = chkbox_completed.Checked; grade.CourseID = int.Parse(ddl_studCourse.SelectedValue); grade.StudentID = studID; var student = sc.StudentsByID(studID); var myBool = student.Grades.FirstOrDefault(x => x.CourseID == grade.CourseID && x.StudentID == grade.StudentID) != null; if (myBool) { var gc = new GradesControl(); gc.UpdateGrade(grade); } else { student.Grades.Add(grade); sc.UpdateStudent(student); } } Response.Redirect($"Course?StudentID={param}"); }
protected void LinkButton1_Click(object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; var id = lb.CommandArgument; var gc = new GradesControl(); int studID = int.Parse(Request.QueryString["StudentID"]); int courseID = int.Parse(id); var studentGradeToRemove = gc.GradeByStudentAndCourseID(studID, courseID); gc.RemoveGrade(studentGradeToRemove); Response.Redirect($"Course?StudentID={studID}"); }