public ActionResult SettingsDisplay([Bind(Include = "TeacherId,TCStartDate,TCEndDate,ChapterDate")] TeacherDateAndTeaching model)
        {
            if (!LoginStatus())
            {
                return(RedirectToAction("Login", "Admins", null));
            }

            Chapter chapter = _db.Chapters.Find(model.ChapterDate.ChapterId);

            if (ModelState.IsValid)
            {
                if (model.TCStartDate >= model.TCEndDate)
                {
                    return(Json("start date should be before end date"));
                }


                TeacherChapterDate chapterDate = new TeacherChapterDate()
                {
                    Chapter     = chapter,
                    Teacher     = _db.Teachers.Find(model.TeacherId),
                    TeacherId   = model.TeacherId,
                    TCStartDate = model.TCStartDate,
                    TCEndDate   = model.TCEndDate,
                    ChapterId   = model.ChapterDate.ChapterId
                };

                bool Exists = _db.TeacherChapterDates.Any(d => d.ChapterId == model.ChapterDate.ChapterId && d.TeacherId == model.TeacherId);
                if (!Exists)
                {
                    _db.TeacherChapterDates.Add(chapterDate);
                    _db.SaveChanges();
                }
                else
                {
                    _db.Entry(chapterDate).State = EntityState.Modified;
                    _db.SaveChanges();
                }
                return(Json(""));
            }
            else
            {
                return(Json("Model is not valid."));
            }
        }
        //Teacher teaching performance
        public ActionResult SettingsDisplay(int?id, int?eduyearid, int?subjectid, int?teacherid)
        {
            if (!LoginStatus())
            {
                return(RedirectToAction("Login", "Admins", null));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            TeacherChapterDate teacherchapterDate = _db.TeacherChapterDates.Where(d => d.ChapterId == id && d.TeacherId == teacherid).FirstOrDefault();

            TeacherSubject teacherSubject = _db.TeacherSubjects.Where(d => d.SubjectId == subjectid && d.TeacherId == teacherid).First();

            Chapter     chapter          = _db.Chapters.Find(id);
            ChapterDate chapterDateExist = _db.ChapterDates.Find(id);

            Subject subjects = _db.Subjects.Find(chapter.SubjectId);

            if (teacherSubject != null)
            {
                TeacherDateAndTeaching model = new TeacherDateAndTeaching()
                {
                    TCStartDate      = DateTime.Now,
                    TCEndDate        = DateTime.Now,
                    SubjectId        = teacherSubject.SubjectId,
                    TeacherId        = teacherSubject.TeacherId,
                    Teacher          = _db.Teachers.Find(teacherSubject.TeacherId),
                    ChapterDate      = chapterDateExist,
                    teachersubject   = teacherSubject,
                    Chapter          = chapter,
                    ClassId          = subjects.ClassesId,
                    teacherTeachings = new List <TeacherTeaching>()
                };

                if (teacherchapterDate != null)
                {
                    model.ChapterId   = eduyearid != null ? 0 : teacherchapterDate.ChapterId;
                    model.Chapter     = chapter;
                    model.TCStartDate = teacherchapterDate.TCStartDate;
                    model.TCEndDate   = teacherchapterDate.TCEndDate;
                    model.ChapterDate = chapterDateExist;
                    model.Teacher     = teacherchapterDate.Teacher;
                    model.TeacherId   = teacherchapterDate.TeacherId;
                    model.ClassId     = subjects.ClassesId;
                }

                List <TeacherTeaching> lstTeacherTeaching = new List <TeacherTeaching>();

                lstTeacherTeaching = _db.TeacherTeachings.Where(d => d.ChapterId == id).ToList();

                var teachingType = _db.ChapterTeachings.Where(d => d.ChapterId == id).OrderBy(d => d.OrderId).ToList();

                foreach (var item in teachingType)
                {
                    if (item.Status)
                    {
                        TeacherTeaching findVal = new TeacherTeaching();
                        findVal = lstTeacherTeaching.Find(d => d.TeachingTypeId == item.TeachingTypeId);

                        TeacherTeaching chapterTeaching = new TeacherTeaching()
                        {
                            OrderId           = item.OrderId,
                            MinVal            = item.MinVal,
                            MaxVal            = item.MaxVal,
                            Marks             = findVal != null ? findVal.Marks : 0,
                            ChapterId         = item.ChapterId,
                            TeachingTypeId    = item.TeachingTypeId,
                            TeacherTeachingId = findVal != null ? findVal.TeacherTeachingId : 0,
                            TeachingType      = _db.TeachingTypes.Find(item.TeachingTypeId)
                        };
                        model.teacherTeachings.Add(chapterTeaching);
                    }
                }


                return(View(model));
            }

            return(View(""));
        }