public JsonResult Index(QuestionOptionViewModel questionOption)
        {
            Question objQuestion = new Question();

            objQuestion.QuestionName = questionOption.QuestionName;
            objQuestion.CategoryId   = questionOption.CategoryId;
            objQuestion.IsActive     = true;
            objQuestion.IsMultiple   = false;
            objquizdbEntities.Questions.Add(objQuestion);
            objquizdbEntities.SaveChanges();

            int questionId = objQuestion.QuestionId;

            foreach (var item in questionOption.ListOfOptions)
            {
                Option objOption = new Option();
                objOption.OptionName = item;
                objOption.QuestionId = questionId;
                objquizdbEntities.Options.Add(objOption);
                objquizdbEntities.SaveChanges();
            }

            Answer objAnswer = new Answer();

            objAnswer.Answertext = questionOption.AnswerText;
            objAnswer.QuestionId = questionId;
            objquizdbEntities.Answers.Add(objAnswer);
            objquizdbEntities.SaveChanges();
            return(Json(new { message = "data Successfilly added.", success = true }, JsonRequestBehavior.AllowGet));
        }
        public async Task <QuestionOptionViewModel> RemoveQuestionOption(int id, [Bind("QuestionIndex")] QuestionOptionViewModel qvm)  // id is of the question option
        {
            if (qvm.QuestionIndex < 0)
            {
                return new QuestionOptionViewModel {
                           ErrorCode = QuestionSetError.FormIndexNotProvided
                }
            }
            ;

            var questionoption = await _context.QuestionOption.FirstOrDefaultAsync(qo => qo.QuestionOptionId == id);

            var question = await _context.Question.Include(qs => qs.QuestionSet)
                           .Include(qs => qs.Options)
                           .FirstOrDefaultAsync(qs => qs.QuestionId == questionoption.QuestionId);

            if (question == null)
            {
                return new QuestionOptionViewModel {
                           ErrorCode = QuestionSetError.NotFound
                }
            }
            ;

            if (!UserCanModifyQuestionSet(question.QuestionSet))
            {
                return new QuestionOptionViewModel {
                           ErrorCode = QuestionSetError.NotAuthorized
                }
            }
            ;


            _context.QuestionOption.Remove(question.Options.Find(qo => qo.QuestionOptionId == questionoption.QuestionOptionId));

            question.Options.RemoveAt(question.Options.FindIndex(qo => qo.QuestionOptionId == questionoption.QuestionOptionId));

            await _context.SaveChangesAsync();

            question.Options = question.Options.OrderBy(qo => qo.Order).ToList();

            for (int index = 0; index < question.Options.Count; index++)
            {
                qvm.Index                   = index;
                qvm.ErrorCode               = QuestionSetError.NoError;
                qvm.QuestionOption          = question.Options[index];
                qvm.QuestionOption.Question = null;
                qvm.QuestionOptionForm     += await _renderService.RenderToStringAsync("_QuestionOptionEditPartial", qvm);
            }

            return(qvm);
        }
        public async Task <QuestionOptionViewModel> AddQuestionOption(int id, [Bind("QuestionIndex")] QuestionOptionViewModel qvm)  // id is of the question, qindex is sortable list index
        {
            if (qvm.QuestionIndex < 0)
            {
                return new QuestionOptionViewModel {
                           ErrorCode = QuestionSetError.FormIndexNotProvided
                }
            }
            ;

            var question = await _context.Question.Include(qs => qs.QuestionSet).FirstOrDefaultAsync(qs => qs.QuestionId == id);

            if (question == null)
            {
                return new QuestionOptionViewModel {
                           ErrorCode = QuestionSetError.NotFound
                }
            }
            ;

            var qset = question.QuestionSet;

            if (!UserCanModifyQuestionSet(qset))
            {
                return new QuestionOptionViewModel {
                           ErrorCode = QuestionSetError.NotAuthorized
                }
            }
            ;

            QuestionOption q = new QuestionOption
            {
                QuestionId = question.QuestionId,
                Name       = ""
            };

            _context.Add(q);
            await _context.SaveChangesAsync();

            int index = await _context.QuestionOption.Where(qs => qs.QuestionId == id).CountAsync() - 1;

            qvm.Index                   = index;
            qvm.ErrorCode               = QuestionSetError.NoError;
            qvm.QuestionOption          = q;
            qvm.QuestionOption.Question = null;
            qvm.QuestionOptionForm      = await _renderService.RenderToStringAsync("_QuestionOptionEditPartial", qvm);

            return(qvm);
        }
        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));
        }
Beispiel #5
0
        public IActionResult Create(QuestionOptionViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var question = new Question
            {
                QuestionText = model.QuestionViewModel.QuestionText
            };

            _context.Add(question);

            _context.SaveChanges();

            var insertedQuestionId = question.Id;



            foreach (var optionFromView in model.OptionViewModel)
            {
                var option = new Option
                {
                    Text       = optionFromView.OptionText,
                    IsCorrect  = optionFromView.IsCorrect,
                    QuestionId = insertedQuestionId
                };

                _context.Add(option);
                _context.SaveChanges();
            }

            TempData["success-msg"] = "Question Saved Successfully";

            ModelState.Clear();

            return(RedirectToAction($"Create"));
        }
Beispiel #6
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));
        }