public List <SubjectLevel> GetQuerySubjectLevel() { List <SubjectLevel> queryList = new List <SubjectLevel>(); try { using (SDBcontext db = new SDBcontext()) { var query = from l in db.tblLevel join s in db.tblSubject on l.Id_Level equals s.Level.Id_Level select new { Stage = l.Stage, Description = s.Description, Credits = s.Credits }; foreach (var q in query) { queryList.Add(new SubjectLevel { Stage = q.Stage, Description = q.Description, Credits = q.Credits }); } } } catch (Exception) { throw; } return(queryList); }
public List <Student> GetStudents() { try { using (SDBcontext db = new SDBcontext()) { return(db.tblStudent.ToList()); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }
public List <Level> GetLevels() { List <Level> levelList = new List <Level>(); try { using (SDBcontext db = new SDBcontext()) { levelList = db.tblLevel.ToList(); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } return(levelList); }
public List <Subject> GetSubjects() { var subjectList = new List <Subject>(); try { using (SDBcontext db = new SDBcontext()) { subjectList = db.tblSubject.ToList(); var orderSubjects = subjectList.OrderBy(x => x.Description); subjectList = orderSubjects.ToList(); } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } return(subjectList); }
public void SaveTeacherSubject(Teacher teacher) { try { using (SDBcontext db = new SDBcontext()) { db.Database.ExecuteSqlCommand("DELETE FROM TeacherSubjects WHERE Teacher_DNI=@id", new SqlParameter("id", teacher.DNI)); db.SaveChanges(); foreach (var subject in teacher.Subjects) { db.Database.ExecuteSqlCommand("INSERT INTO TeacherSubjects VALUES(@dni,@di)", new SqlParameter("dni", teacher.DNI), new SqlParameter("di", subject.Id_Subject)); db.SaveChanges(); } } } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } }