public void UpdateStudentClass(int studentId, BCStudentClass studentClass)
        {
            using (var dbContext = new AttendanceSystemDB(_connectionString))
            {
                //var alreadyExists = dbContext.StudentClasses.FirstOrDefault(s => s.StudentId == studentId && s.ClassId == classId) != null ? true : false;

                if (studentClass.BCStudentClassId != 0)
                {
                    //StudentClass studentClass = dbContext.StudentClasses.FirstOrDefault(s => s.StudentId == studentId && s.ClassId == classId);
                    //studentClass.IsActive = true;

                    dbContext.Entry <BCStudentClass>(studentClass).State = EntityState.Modified;
                }
                else
                {
                    BCStudentClass NewStudentClass = new BCStudentClass {
                        BCStudentId = studentId, BCClassId = studentClass.BCClassId, IsActive = true
                    };

                    dbContext.BCStudentClasses.Add(NewStudentClass);
                }

                dbContext.SaveChanges();
            }
        }
 public void UpdateAttendance(BCAttendance attendance)
 {
     using (var dbContext = new AttendanceSystemDB(_connectionString))
     {
         dbContext.Entry <BCAttendance>(attendance).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
 public void UpdateStudent(BCStudent student)
 {
     using (var dbContext = new AttendanceSystemDB(_connectionString))
     {
         dbContext.Entry <BCStudent>(student).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
 public void UpdateTeacher(BCTeacher teacher)
 {
     using (var dbContext = new AttendanceSystemDB(_connectionString))
     {
         dbContext.Entry <BCTeacher>(teacher).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
 public void UpdateClass(BCClass c)
 {
     using (var dbContext = new AttendanceSystemDB(_connectionString))
     {
         dbContext.Entry <BCClass>(c).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
        public void MarkStudentClassesInactive(int studentId)
        {
            using (var dbContext = new AttendanceSystemDB(_connectionString))
            {
                var studentclasses = dbContext.BCStudentClasses.Where(s => s.BCStudentId == studentId).ToList();

                foreach (var c in studentclasses)
                {
                    c.IsActive = false;
                    dbContext.Entry <BCStudentClass>(c).State = EntityState.Modified;
                    dbContext.SaveChanges();
                }
            }
        }
        public void MarkTeacherSubjectsInactive(int teacherId)
        {
            using (var dbContext = new AttendanceSystemDB(_connectionString))
            {
                var teacherSubjects = dbContext.BCTeacherSubjects.Where(t => t.BCTeacherId == teacherId).ToList();

                foreach (var s in teacherSubjects)
                {
                    s.IsActive = false;
                    dbContext.Entry <BCTeacherSubject>(s).State = EntityState.Modified;
                    dbContext.SaveChanges();
                }
            }
        }
        public void UpdateTeacherSubjects(int teacherId, BCTeacherSubject subject)
        {
            using (var dbContext = new AttendanceSystemDB(_connectionString))
            {
                if (subject.BCTeacherSubjectId != 0)
                {
                    dbContext.Entry <BCTeacherSubject>(subject).State = EntityState.Modified;
                }
                else
                {
                    BCTeacherSubject teacherSubject = new BCTeacherSubject {
                        BCTeacherId = teacherId, Subject = subject.Subject, IsActive = true
                    };

                    dbContext.BCTeacherSubjects.Add(teacherSubject);
                }

                dbContext.SaveChanges();
            }
        }