public static List<Subjects> GetAllSubjects() { DataTable dsSubjects = SqlHelper.ExecuteDataset(SqlHelper.Connect, CommandType.Text, "select subjects.*,classes.classname from subjects inner join Classes on Classes.ClassId=Subjects.ClassID order by Classid").Tables[0]; List<Subjects> subjectsList = new List<Subjects>(); foreach (DataRow dr in dsSubjects.Rows) { Subjects subjectModel = new Subjects(); subjectModel.SubjectID = dr["SubjectID"].ToString(); subjectModel.SubjectName = dr["SubjectName"].ToString(); subjectModel.ClassName = dr["ClassName"].ToString(); subjectModel.ClassID = dr["ClassID"].ToString(); subjectsList.Add(subjectModel); } return subjectsList; }
public static List<Subjects> GetAllClassesRelatedWithTeacher() { // DataTable dsSubjects = SqlHelper.ExecuteDataset(SqlHelper.Connect, CommandType.Text, "select * from Classes Where ClassID in (Select ClassID from Teachers where UIDFK=@UIDFK)", new SqlParameter("@UIDFK", HttpContext.Current.Session["SessionUserid"].ToString())).Tables[0]; DataTable dsSubjects = SqlHelper.ExecuteDataset(SqlHelper.Connect, CommandType.Text, "select * from Classes ").Tables[0]; List<Subjects> classList = new List<Subjects>(); foreach (DataRow dr in dsSubjects.Rows) { Subjects classModel = new Subjects(); classModel.ClassName = dr["ClassName"].ToString(); classModel.ClassID = dr["ClassID"].ToString(); classList.Add(classModel); } return classList; }
public static List<Subjects> GetSubjectsByTeacherID(long ClassIDFK) { string TeacherSubjects = GetTeacherSubjectsArray(); SqlParameter[] param = { new SqlParameter("@TchrSub",TeacherSubjects), new SqlParameter("@ClassIDFK",ClassIDFK) }; // DataTable dsSubjects = SqlHelper.ExecuteDataset(SqlHelper.Connect, CommandType.Text, "Select * from Subjects where SubjectID in (Select Item from dbo.SplitString(@TchrSub))", param).Tables[0]; DataTable dsSubjects = SqlHelper.ExecuteDataset(SqlHelper.Connect, CommandType.Text, "Select * from Subjects where ClassID=@ClassIDFK", param).Tables[0]; List<Subjects> subjectsList = new List<Subjects>(); foreach (DataRow dr in dsSubjects.Rows) { Subjects subjectModel = new Subjects(); subjectModel.SubjectID = dr["SubjectID"].ToString(); subjectModel.SubjectName = dr["SubjectName"].ToString(); subjectModel.ClassID = ClassIDFK.ToString(); subjectsList.Add(subjectModel); } return subjectsList; }