public JsonResult addtest(QuestionOptionViewModel QuestionOption)
        {
            //CourseDBHandle gc = new CourseDBHandle();
            //List<CourseDBHandle> list = gc.GetCourse();
            //ViewBag.course = new SelectList(list, "courseId", "courseName");
            OnlineTest q = new OnlineTest();

            q.Role_Id = Convert.ToInt32(Session["RoleId"]);


            q.UserId = Convert.ToInt32(Session["Ad"]);


            //OnlineTest test = new OnlineTest();
            q.CourseId     = QuestionOption.CourseId;
            q.QuestionName = QuestionOption.QuestionName;
            q.IsActive     = true;
            q.CreatedDate  = DateTime.Now;
            q.Duration     = "1 hour";
            q.IsMultiple   = false;
            db.OnlineTests.Add(q);
            db.SaveChanges();

            int questionId = q.QuestionId;

            foreach (var item in QuestionOption.ListOfOptions)
            {
                OnlineTestQuestionOption objoption = new OnlineTestQuestionOption();
                objoption.OptionName = item;
                objoption.QuestionId = questionId;
                db.OnlineTestQuestionOptions.Add(objoption);
                db.SaveChanges();
            }
            OnlineTestAnswer objanswer = new OnlineTestAnswer();

            objanswer.AnswerText = QuestionOption.AnswerText;
            objanswer.RoleId     = Convert.ToInt32(Session["RoleId"]);
            objanswer.UserId     = Convert.ToInt32(Session["Ad"]);
            objanswer.SchoolId   = Convert.ToInt32(Session["Ad"]);



            objanswer.QuestionId = questionId;
            db.OnlineTestAnswers.Add(objanswer);
            db.SaveChanges();

            return(Json(new { message = " Successfully Added", success = true }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public JsonResult addonlinetest(QuestionOptionViewModel QuestionOption)
        {
            int teacherid = Convert.ToInt32(Session["Teacher"]);

            int tempclassid;
            int schoolid;
            int originalclassid;
            var getteacherid = db.Teachers.Find(teacherid);

            tempclassid = getteacherid.Class_Id;
            var classid = db.Tbl_Class.Where(x => x.Class_Id == tempclassid).SingleOrDefault();

            originalclassid = classid.Class_Id;


            CourseDBHandle gc = new CourseDBHandle();

            List <tbl_CourseAssigntoTeacherValidation> list = gc.GetTeacherAssignedCourse(teacherid, originalclassid);

            ViewBag.course = new SelectList(list, "courseId", "courseName");
            OnlineTest q = new OnlineTest();

            q.Role_Id = Convert.ToInt32(Session["RoleId"]);
            q.UserId  = Convert.ToInt32(Session["Teacher"]);
            var getteachid = db.Teachers.Find(teacherid);

            schoolid   = getteachid.School_Id;
            q.SchoolId = schoolid;
            //OnlineTest test = new OnlineTest();
            q.CourseId     = QuestionOption.CourseId;
            q.QuestionName = QuestionOption.QuestionName;
            q.IsActive     = true;
            q.ClassId      = originalclassid;
            q.CreatedDate  = DateTime.Now;
            q.Duration     = "1 hour";
            q.IsMultiple   = false;
            db.OnlineTests.Add(q);
            db.SaveChanges();

            int questionId = q.QuestionId;

            foreach (var item in QuestionOption.ListOfOptions)
            {
                OnlineTestQuestionOption objoption = new OnlineTestQuestionOption();
                objoption.OptionName = item;
                objoption.QuestionId = questionId;
                db.OnlineTestQuestionOptions.Add(objoption);
                db.SaveChanges();
            }
            OnlineTestAnswer objanswer = new OnlineTestAnswer();

            objanswer.AnswerText = QuestionOption.AnswerText;
            objanswer.RoleId     = Convert.ToInt32(Session["RoleId"]);
            objanswer.UserId     = Convert.ToInt32(Session["Teacher"]);
            objanswer.SchoolId   = schoolid;



            objanswer.QuestionId = questionId;
            db.OnlineTestAnswers.Add(objanswer);
            db.SaveChanges();

            return(Json(new { message = "Data Successfully Added", success = true }, JsonRequestBehavior.AllowGet));
        }