Exemple #1
0
        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);
        }
Exemple #2
0
 public List <Student> GetStudents()
 {
     try
     {
         using (SDBcontext db = new SDBcontext())
         {
             return(db.tblStudent.ToList());
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message.ToString());
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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());
            }
        }