public List <QuestionFuctionReturn> QuestionSubTopicSpecific(QuestionFunction type) { List <QuestionFuctionReturn> tests = new List <QuestionFuctionReturn>(); try { tests = _testgenerate_object.QuestionSubTopicSpecific(type); if (tests != null) { return(tests); } else { throw new OASCustomException("Null data encountered."); } } catch (SqlException sqlex) { log.Error(sqlex); } catch (OASCustomException customex) { log.Error(customex.Message); } catch (Exception ex) { log.Error(ex.Message); } return(tests); }
public IHttpActionResult QuestionSubTopicSpecific(int userid, QuestionFunction type) { List <QuestionFuctionReturn> questions = null; try { if (ModelState.IsValid) { questions = _bltestgenerate.QuestionSubTopicSpecific(type); if (questions.Count == 0) { log.Error("Questions failed to generate"); return(NotFound()); } else { return(Ok(questions)); } } else { log.Error("Invalid model state encountered."); return(BadRequest(ModelState)); } } catch (Exception ex) { log.Error(ex); return(BadRequest(ModelState)); } }
public List <QuestionFuctionReturn> QuestionSubTopicSpecific(QuestionFunction type) { List <QuestionFuctionReturn> questionbank = new List <QuestionFuctionReturn>(); var questions = ( from topic in context.Topics join questionbank_bank in context.QuestionBanks on topic.TopicID equals questionbank_bank.TopicID join difficultylevel in context.DifficultyLevels on questionbank_bank.DifficultyLevelID equals difficultylevel.DifficultyLevelID where difficultylevel.DifficultyLevelID == type.dfid && topic.TopicID == type.topicid select new { DifficultyLevelID = questionbank_bank.DifficultyLevelID, TopicID = questionbank_bank.TopicID, Question = questionbank_bank.Question, Option1 = questionbank_bank.Option1, Option2 = questionbank_bank.Option2, Option3 = questionbank_bank.Option3, Option4 = questionbank_bank.Option4, Answer = questionbank_bank.Answer } ).OrderBy(x => Guid.NewGuid()).Take(10).ToList(); int i = 0; foreach (var q in questions) { questionbank.Add(new QuestionFuctionReturn() { Question = q.Question, Option1 = q.Option1, Option2 = q.Option2, Option3 = q.Option3, Option4 = q.Option4, Answer = q.Answer }); } //For generating new test entry int topic_id = 0, df_id = 0; for (i = 0; i < 1; i++) { topic_id = questions[0].TopicID; df_id = questions[0].DifficultyLevelID; } Test newtest = new Test(); newtest.TotalQuestions = 10; newtest.TotalMarks = 10; newtest.TotalDuration = DateTime.Now; newtest.TopicID = topic_id; newtest.DifficultyLevelID = df_id; TestOperations ctx = new TestOperations(); ctx.CreateTest(newtest); return(questionbank); }