public static UserProfileQuestionsResults FetchUserProfileQuestions(Guid SessionId) { UserProfileQuestionsResults questionResults = new UserProfileQuestionsResults(); try { AgileMindEntities agileDB = new AgileMindEntities(); t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First(); if (session != null) { questionResults.QuestionList = agileDB.FetchQuestionAnswer_ByLoginId(session.LoginId).ToList(); questionResults.Success = true; } else { questionResults.Error = "Could not find sessionId"; } } catch (Exception ex) { questionResults.Error = ex.Message; } return questionResults; }
public static ProfileQuizQuestionRequest FetchRandomQuizQuestions(Guid SessionId, int QuestionCount) { ProfileQuizQuestionRequest request = new ProfileQuizQuestionRequest(); try { AgileMindEntities agileDB = new AgileMindEntities(); t_LoginSession session = (from loginSession in agileDB.t_LoginSession where loginSession.LoginSessionId == SessionId && loginSession.ValidTill > DateTime.Now select loginSession).First(); if (session != null) { List<vwQuestionAnswer> questionList = agileDB.FetchQuestionAnswer_ByLoginId(session.LoginId).ToList(); //Make sure we only get active and ones with an actual answer. questionList = questionList.FindAll(delegate(vwQuestionAnswer findQA) { return findQA.Active && !string.IsNullOrEmpty(findQA.Answer); }); Random rand = new Random(); for (int count = 0; count < QuestionCount; count++) { ProfileQuizQuestion newQA = new ProfileQuizQuestion(); int index = rand.Next(questionList.Count); vwQuestionAnswer foundA = questionList[index]; newQA.Answer = foundA.Answer; newQA.Question = foundA.Question; request.QuestionList.Add(newQA); } request.Success = true; } else { request.Error = "Could not find sessionId"; } } catch (Exception ex) { request.Error = ex.Message; } return request; }