//public JsonResult StudentByClass(int id)
        //{
        //    var result1 = db.AspNetSubjects.Where(x => x.ClassID == id).ToList();
        //    var obj = JsonConvert.SerializeObject(result1);
        //       return Json(obj, JsonRequestBehavior.AllowGet);

        //}


        // GET: AspnetSubjectTopics/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspnetSubjectTopic aspnetSubjectTopic = db.AspnetSubjectTopics.Find(id);

            if (aspnetSubjectTopic == null)
            {
                return(HttpNotFound());
            }

            //Teacher Subjects



            int?SubjectId = aspnetSubjectTopic.SubjectId;

            GenericSubject Subject = db.GenericSubjects.Where(x => x.Id == SubjectId).FirstOrDefault();



            //    ViewBag.ClassID = new SelectList(db.AspNetClasses, "Id", "ClassName", Subject.ClassID);
            //     ViewBag.SubjectId = new SelectList(db.GenericSubjects.Where(x=>x.SubjectType == Subject.SubjectType), "Id", "SubjectName", aspnetSubjectTopic.SubjectId);
            ViewBag.SubjectId = new SelectList(db.GenericSubjects.Where(x => x.SubjectType == Subject.SubjectType), "Id", "SubjectName", aspnetSubjectTopic.SubjectId);


            ViewBag.CTId = Subject.SubjectType;

            ViewBag.OrderBy = aspnetSubjectTopic.OrderBy;

            return(View(aspnetSubjectTopic));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Description,SubjectId,FAQ,OrderBy")] AspnetSubjectTopic aspnetSubjectTopic)
        {
            aspnetSubjectTopic.StartDate = null;
            aspnetSubjectTopic.EndDate   = null;

            if (ModelState.IsValid)
            {
                db.AspnetSubjectTopics.Add(aspnetSubjectTopic);
                db.SaveChanges();
                return(RedirectToAction("ViewTopicsAndLessons"));
            }

            var UserId = User.Identity.GetUserId();
            //Teacher Subjects
            var SubjectofCurrentSessionTeacher = from subject in db.GenericSubjects
                                                 join TeacherSubject in db.Teacher_GenericSubjects on subject.Id equals TeacherSubject.SubjectId
                                                 join employee in db.AspNetEmployees on TeacherSubject.TeacherId equals employee.Id
                                                 where employee.UserId == UserId
                                                 select new
            {
                subject.Id,
                subject.SubjectName,
            };

            ViewBag.SubjectId = new SelectList(SubjectofCurrentSessionTeacher, "Id", "SubjectName", aspnetSubjectTopic.SubjectId);
            return(View(aspnetSubjectTopic));
        }
        public ActionResult Create(int id)
        {
            if (id != 0)
            {
                AspnetSubjectTopic aspnetSubjectTopic = db.AspnetSubjectTopics.Find(id);


                int?           SubjectId = aspnetSubjectTopic.SubjectId;
                GenericSubject Subject   = db.GenericSubjects.Where(x => x.Id == SubjectId).FirstOrDefault();

                ViewBag.TopicExist = 1;

                ViewBag.TopicId   = id;
                ViewBag.SubjectId = aspnetSubjectTopic.SubjectId;
                ViewBag.CTId      = Subject.SubjectType;

                return(View());
            }
            else
            {
                ViewBag.TopicId    = null;
                ViewBag.SubjectId  = null;
                ViewBag.CTId       = null;
                ViewBag.TopicExist = 0;
                //   ViewBag.TopicId = new SelectList(db.AspnetSubjectTopics, "Id", "Name");
                // ViewBag.ClassID = new SelectList(db.AspNetClasses, "Id", "ClassName");

                return(View());
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            AspnetSubjectTopic aspnetSubjectTopic = db.AspnetSubjectTopics.Find(id);

            db.AspnetSubjectTopics.Remove(aspnetSubjectTopic);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit([Bind(Include = "Id,Name,Description,StartDate,EndDate,SubjectId,FAQ,OrderBy")] AspnetSubjectTopic aspnetSubjectTopic)
        {
            if (ModelState.IsValid)
            {
                db.Entry(aspnetSubjectTopic).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("ViewTopicsAndLessons"));
            }

            ViewBag.SubjectId = new SelectList(db.GenericSubjects, "Id", "SubjectName", aspnetSubjectTopic.SubjectId);
            return(View(aspnetSubjectTopic));
        }
        // GET: AspnetSubjectTopics/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspnetSubjectTopic aspnetSubjectTopic = db.AspnetSubjectTopics.Find(id);

            if (aspnetSubjectTopic == null)
            {
                return(HttpNotFound());
            }
            return(View(aspnetSubjectTopic));
        }
        //public JsonResult StudentByClass(int id)
        //{
        //    var result1 = db.AspNetSubjects.Where(x => x.ClassID == id).ToList();
        //    var obj = JsonConvert.SerializeObject(result1);
        //       return Json(obj, JsonRequestBehavior.AllowGet);

        //}


        // GET: AspnetSubjectTopics/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspnetSubjectTopic aspnetSubjectTopic = db.AspnetSubjectTopics.Find(id);

            if (aspnetSubjectTopic == null)
            {
                return(HttpNotFound());
            }

            //Teacher Subjects



            int?SubjectId = aspnetSubjectTopic.SubjectId;

            GenericSubject Subject = db.GenericSubjects.Where(x => x.Id == SubjectId).FirstOrDefault();


            var UserId = User.Identity.GetUserId();


            var SubjectofCurrentSessionTeacher = from subject in db.GenericSubjects
                                                 join TeacherSubject in db.Teacher_GenericSubjects on subject.Id equals TeacherSubject.SubjectId
                                                 join employee in db.AspNetEmployees on TeacherSubject.TeacherId equals employee.Id
                                                 where employee.UserId == UserId && subject.SubjectType == Subject.SubjectType
                                                 select new
            {
                subject.Id,
                subject.SubjectName,
            };

            //    ViewBag.ClassID = new SelectList(db.AspNetClasses, "Id", "ClassName", Subject.ClassID);
            //     ViewBag.SubjectId = new SelectList(db.GenericSubjects.Where(x=>x.SubjectType == Subject.SubjectType), "Id", "SubjectName", aspnetSubjectTopic.SubjectId);
            ViewBag.SubjectId = new SelectList(SubjectofCurrentSessionTeacher, "Id", "SubjectName", aspnetSubjectTopic.SubjectId);


            ViewBag.CTId = Subject.SubjectType;

            return(View(aspnetSubjectTopic));
        }
        public ActionResult CheckTopicOrderBy(string SubjectId, string OrderBy)
        {
            int SubId        = Convert.ToInt32(SubjectId);
            int OrderByValue = Convert.ToInt32(OrderBy);

            var TopicExist = "";
            AspnetSubjectTopic subjectTopic = db.AspnetSubjectTopics.Where(x => x.SubjectId == SubId && x.OrderBy == OrderByValue).FirstOrDefault();

            if (subjectTopic == null)
            {
                TopicExist = "No";
            }
            else
            {
                TopicExist = "Yes";
            }


            return(Json(TopicExist, JsonRequestBehavior.AllowGet));
        }