public int Add(AssignmentRoutineViewModel arvm)
        {
            tblAssignmentRoutine tb = new tblAssignmentRoutine();

            tb.Assignment_Name         = arvm.Assignment_Name;
            tb.Teacher_Id              = arvm.Teacher_Id;
            tb.Assignment_Release_Date = arvm.Assignment_Release_Date;
            tb.Deadline    = arvm.Deadline;
            tb.Section_Id  = arvm.Section_Id;
            tb.Faculty_Id  = arvm.Faculty_Id;
            tb.Semester_Id = arvm.Semester_Id;
            tb.YearBatchId = arvm.Year_Batch_Id;


            _db.tblAssignmentRoutines.Add(tb);
            _db.SaveChanges();


            tblStudentRoutineRelation tsr = new tblStudentRoutineRelation();
            var studnet = _db.tblStudents.Where(s => s.Faculty_Id == tb.Faculty_Id && s.Section_Id == tb.Section_Id && s.Semester_Id == tb.Semester_Id && s.YearBatchId == tb.YearBatchId).ToList();

            foreach (var item in studnet)
            {
                tsr.RoutineId = tb.Routine_Id;
                tsr.StudentId = item.Student_Id;
                _db.tblStudentRoutineRelations.Add(tsr);
                _db.SaveChanges();
            }
            return(0);
        }
        public int Update(AssignmentRoutineViewModel arvm)
        {
            bool fieldChange        = false;
            tblAssignmentRoutine tb = _db.tblAssignmentRoutines.Where(a => a.Routine_Id == arvm.Id).FirstOrDefault();

            if (tb.Section_Id == arvm.Section_Id && tb.Faculty_Id == arvm.Faculty_Id && tb.Semester_Id == arvm.Semester_Id && tb.YearBatchId == arvm.Year_Batch_Id)
            {
                fieldChange = false;
            }
            else
            {
                fieldChange = true;
            }
            tb.Assignment_Name         = arvm.Assignment_Name;
            tb.Teacher_Id              = arvm.Teacher_Id;
            tb.Assignment_Release_Date = arvm.Assignment_Release_Date;
            tb.Deadline    = arvm.Deadline;
            tb.Section_Id  = arvm.Section_Id;
            tb.Faculty_Id  = arvm.Faculty_Id;
            tb.Semester_Id = arvm.Semester_Id;
            tb.YearBatchId = arvm.Year_Batch_Id;
            _db.SaveChanges();
            //tblStudentRoutineRelation tsr = new tblStudentRoutineRelation();
            //var studnet = _db.tblStudents.Where(s => s.Faculty_Id == tb.Faculty_Id && s.Section_Id == tb.Section_Id && s.Semester_Id == tb.Semester_Id && s.YearBatchId == tb.YearBatchId).ToList();
            if (fieldChange)
            {
                var studentlist = _db.tblStudentRoutineRelations.Where(s => s.RoutineId == tb.Routine_Id).ToList();
                foreach (var item in studentlist)
                {
                    _db.tblStudentRoutineRelations.Remove(item);
                }
                tblStudentRoutineRelation tsr = new tblStudentRoutineRelation();
                var studnet = _db.tblStudents.Where(s => s.Faculty_Id == tb.Faculty_Id && s.Section_Id == tb.Section_Id && s.Semester_Id == tb.Semester_Id && s.YearBatchId == tb.YearBatchId).ToList();
                foreach (var item in studnet)
                {
                    tsr.RoutineId = tb.Routine_Id;
                    tsr.StudentId = item.Student_Id;
                    _db.tblStudentRoutineRelations.Add(tsr);
                    _db.SaveChanges();
                }
            }

            return(0);
        }