public ActionResult AttemptReport(int activityId, int attempt) { try { TblUser sessionUser = (TblUser)Session["UserSession"]; List <TblQuiz> lstAllQuiz = new List <TblQuiz>(); lstAllQuiz = quizRepository.GetQuizForLaunch(activityId, sessionUser.UserId); //var attempt = quizRepository.GetQuizAttemptByUserID(activityId, sessionUser.UserId); List <TblRespons> quizResponses = new List <TblRespons>(); quizResponses = quizRepository.GetQuizResponsesByUserID(activityId, sessionUser.UserId, attempt); lstAllQuiz[0].TblResponses = quizResponses; var noOfQuestions = lstAllQuiz[0].TblQuestions.Where(x => x.QuestionTypeId == 1 || x.QuestionTypeId == 2).Count(); var score = quizRepository.GetQuizScoreByUserID(activityId, sessionUser.UserId, attempt); //lstAllQuiz[0].Score = Convert.ToInt32(score.Score); if (score.Score == 0) { lstAllQuiz[0].Score = "0%"; } else { lstAllQuiz[0].Score = Convert.ToString(Math.Round(Convert.ToDecimal(score.Score * 100 / noOfQuestions), 2)); } lstAllQuiz[0].completeTime = score.completedTime; JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnReviewData = json_serializer.Serialize(lstAllQuiz[0]); //var attemptList = rpt.GetDetailReportForLearner(sessionUser.UserId, sessionUser.TenantId, activityId); return(View("AttemptReport", lstAllQuiz[0])); } catch (Exception ex) { newException.AddException(ex); return(View("AttemptReport")); } }
public ActionResult StartQuiz() { try { int UserId = Convert.ToInt32(Session["Enquiry"]); int QuizId = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SurveyId"]); var result = quizRepository.AssignQuiz(QuizId, UserId, null); var lstAllQuiz = quizRepository.GetQuizForLaunch(QuizId, UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); return(View("InitialAssessment", lstAllQuiz[0])); } catch (Exception ex) { newException.AddException(ex); TempData["Issue"] = "Issue Occured"; List <SelectListItem> countriesItem = new List <SelectListItem>(); countriesItem = (List <SelectListItem>)Session["countriesItem"]; return(View("TestYourKnowledge")); } }
public async Task <ActionResult> LaunchQuiz(int QuizId, string code) //public ActionResult LaunchQuiz(int QuizId, string code) { //newException.AddDummyException("Quiz ID First - " + Convert.ToString(QuizId)); bool isPlek = false; try { TblUser sessionUser = (TblUser)Session["UserSession"]; if (string.IsNullOrEmpty(code)) { QuizSession quizForSession = new QuizSession(); quizForSession.QuizId = Convert.ToInt32(QuizId); quizForSession.isUsed = false; lstQuiz.Add(quizForSession); Session["QuizId"] = lstQuiz; if (string.IsNullOrEmpty(Convert.ToString(Session["QuizId"]))) { newException.AddDummyException("Quiz Id in LaunchQuiz is Null"); } } List <TblQuiz> lstAllQuiz = new List <TblQuiz>(); if (sessionUser == null) { TenantRepository tr = new TenantRepository(); List <TblTenant> tenantDetails = new List <TblTenant>(); string host = Request.Url.Host; var tenantList1 = tr.VerifyTenantDomain(host); if (tenantList1.Count > 0) { if (tenantList1[0].TenantId == 6) { if (string.IsNullOrEmpty(code)) { return(Redirect("https://pumplace.plek.co/oidc/auth?client_id=1663f8ca-7b8a-42eb-ae3b-845e32be1baf&scope=openid&response_type=code&redirect_uri=https://quiz.rockettech.co.nz/")); } else { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*"); string tokenApi = "https://pumplace.plek.co/oidc/token"; var values = new Dictionary <string, string>(); values.Add("client_id", "1663f8ca-7b8a-42eb-ae3b-845e32be1baf"); values.Add("client_secret", "TZD4Jr837e6uymsJdyxH2jk8qxGQiK7gXDCmYqtC"); values.Add("grant_type", "authorization_code"); values.Add("code", code); values.Add("redirect_uri", "https://quiz.rockettech.co.nz/"); var content = new FormUrlEncodedContent(values); var responseTask = await client.PostAsync(tokenApi, content); var result = await responseTask.Content.ReadAsStringAsync(); var data = (JObject)JsonConvert.DeserializeObject(result); string token = data["access_token"].Value <string>();//Access Token Received //Now get User Details string userApi = "https://pumplace.plek.co/oidc/me"; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); HttpResponseMessage response = await client.GetAsync(userApi); if (response.IsSuccessStatusCode) { string jsondata = await response.Content.ReadAsStringAsync(); var userData = (JObject)JsonConvert.DeserializeObject(jsondata); string email = userData["email"].Value <string>(); string name = userData["username"].Value <string>(); var userId = ur.IsUserExist(email, Request.Url.Host); if (userId == 0) { try { //Create user TblUser newUser = new TblUser(); newUser.FirstName = name; newUser.EmailId = email; newUser.RoleId = 3; newUser.IsActive = true; newUser.CreatedBy = 1; CommonFunctions common = new CommonFunctions(); newUser.Password = common.GetEncodePassword("123456"); var tenantList = tr.VerifyTenantDomain(Request.Url.Host); newUser.TenantId = tenantList[0].TenantId; var newUserId = ur.AddUser(newUser); if (newUserId > 0) { //Assign Quiz to Newly Created User //newException.AddDummyException("111 - " + Convert.ToString(QuizId)); var objQuiz = quizRepository.GetQuizByID(Convert.ToInt32(QuizId)); if (objQuiz != null) { if (objQuiz[0] != null) { if (objQuiz[0].TenantId == 6) { var assign = quizRepository.AssignQuiz(Convert.ToInt32(QuizId), newUserId, null); } } } userId = newUserId; } } catch (Exception ex) { newException.AddException(ex); } } else { //check Quiz assigned or not var isAssigned = quizRepository.CheckQuizAssignedUser(Convert.ToInt32(QuizId), userId); if (!isAssigned) { newException.AddDummyException("222 - " + QuizId); var objQuiz = quizRepository.GetQuizByID(Convert.ToInt32(QuizId)); if (objQuiz != null) { if (objQuiz[0] != null) { if (objQuiz[0].TenantId == 6) { var assign = quizRepository.AssignQuiz(Convert.ToInt32(QuizId), userId, null); } } } } } List <TblUser> tblUser = ur.GetUserById(userId); Session["UserSession"] = tblUser[0]; lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), userId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); isPlek = true; } } } } if (tenantList1[0].TenantId == 9) { //newException.AddDummyException("In - 111 "); CommonFunctions common = new CommonFunctions(); var password = common.GetEncodePassword("123456"); TblUser tblUser = ur.IsValidUser("*****@*****.**", password, Request.Url.Host); lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), tblUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); //newException.AddDummyException("In - 222 "); isPlek = true; } } } else { if (sessionUser.TenantId == 6) { isPlek = true; //check Quiz assigned or not var isAssigned = quizRepository.CheckQuizAssignedUser(Convert.ToInt32(QuizId), sessionUser.UserId); //newException.AddDummyException(Convert.ToString(isAssigned)); if (!isAssigned) { //newException.AddDummyException("333 - " + QuizId); var objQuiz = quizRepository.GetQuizByID(Convert.ToInt32(QuizId)); if (objQuiz != null) { if (objQuiz[0] != null) { if (objQuiz[0].TenantId == 6) { var assign = quizRepository.AssignQuiz(Convert.ToInt32(QuizId), sessionUser.UserId, null); lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), sessionUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); } } } } else { lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), sessionUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); } } if (sessionUser.TenantId == 9) { //newException.AddDummyException("In - 111 "); CommonFunctions common = new CommonFunctions(); var password = common.GetEncodePassword("123456"); TblUser tblUser = ur.IsValidUser("*****@*****.**", password, Request.Url.Host); lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), tblUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); //newException.AddDummyException("In - 222 "); isPlek = true; } else { lstAllQuiz = quizRepository.GetQuizForLaunch(Convert.ToInt32(QuizId), sessionUser.UserId); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; lstAllQuiz[0].hdnLaunchData = json_serializer.Serialize(lstAllQuiz[0]); } } if (isPlek) { return(View("LaunchQuizForPlek", lstAllQuiz[0])); } else { return(View("LaunchQuizNew", lstAllQuiz[0])); } } catch (Exception ex) { newException.AddException(ex); if (isPlek) { return(View("LaunchQuizForPlek")); } else { return(View("LaunchQuizNew")); } } }