public ActionResult PassingTest(PassingTestViewModel model) { bool isSuccess = false; var test = testService.GetById(model.Id); int userId = userService.GetOneByPredicate(u => u.UserName == User.Identity.Name).Id; var testResults = testService.CheckAnswers(model.Id, model.Results); var runtime = (DateTime.UtcNow - model.StartTest); if (testResultService.CheckPercentAnswers(testResults, test.MinToSuccess) && testResultService.CheckTime(test.TimeLimit, runtime)) { isSuccess = true; } var bllTestResult = new BllTestResult { TestId = model.Id, UserId = userId, Runtime = runtime, DateComplete = DateTime.Now, IsSuccess = isSuccess, Results = testResults.ToList() }; testResultService.Create(bllTestResult); var mvcTestResult = bllTestResult.ToMvcStatistics(); mvcTestResult.TimeLimit = test.TimeLimit; mvcTestResult.MinToSuccess = test.MinToSuccess; mvcTestResult.PercentCorrectAnswers = testResultService.GetPercentGoodAnswers(testResults); if (Request.IsAjaxRequest()) { return(PartialView("_Statistics", mvcTestResult)); } return(View("_Statistics", mvcTestResult)); }
/// <summary> /// 删除 /// </summary> public JsonResult SubmitTest(string id) { var json = new ModJsonResult(); try { int RightNum = Convert.ToInt32(Request["RightNum"] == null ? "" : Request["RightNum"]); var lmid = (Request["lmid"] == null ? "" : Request["lmid"]); var session = Session["ss"]; var uu = Session["uu"]; var gg = Session["gg"]; /*string url2 = HttpContext.Request.Url.Query; * url2 = url2.Replace("?", ""); * string[] urlpa = url2.Split('&'); * int co = 0; * string session = ""; * foreach (string s in urlpa) * { * string[] val = s.Split('='); * string co2=val[co]; * if (co2=="sid"){ * session = val[co + 1]; * } * }*/ BllTestResult bll = new BllTestResult(); ModTestResult model = new ModTestResult(); model.uid = uu.ToString(); model.qid = lmid; model.score = RightNum.ToString(); model.date = session.ToString(); float d = (float)RightNum / 100; int result = bll.Insert(model); String cc2 = "http://adapt2.sis.pitt.edu/cbum/um?app=37&act=" + model.qid + "&sub=" + lmid + "_test" + "&grp=" + gg + "&usr="******"&sid=" + model.date + "&res=" + d + "&svc=" + "m"; Process ps = new Process(); Process.Start(cc2); // HttpWebResponse rs = (HttpWebResponse)HttpWebRequest.Create(cc2.ToString()).GetResponse(); // Response.Write("<script language='javascript'>window.open('" + cc2 + "');</script>"); if (result > 0) { json.success = true; } else { json.success = false; json.msg = " Failed!"; } } catch (Exception ex) { json.success = false; json.msg = "Error:" + ex.Message; } return(Json(json, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Maps BllTestResult entity to TestResultViewModel entity. /// </summary> /// <param name="testResult"> BllTestResult instance.</param> /// <returns> TestResultViewModel instance.</returns> public static TestResultViewModel ToTestResultViewModel(this BllTestResult testResult) { return(new TestResultViewModel { Id = testResult.Id, DateTime = testResult.DateTime, Grade = testResult.Grade, TimeSpent = testResult.TimeSpent, UserId = testResult.UserId, TestId = testResult?.Test.Id, TestName = testResult?.Test.Name }); }
public static ResultStatisticsViewModel ToMvcStatistics(this BllTestResult bllTestResult) { if (bllTestResult == null) { return(null); } return(new ResultStatisticsViewModel() { UserId = bllTestResult.UserId, Runtime = bllTestResult.Runtime, IsSuccess = bllTestResult.IsSuccess, Results = bllTestResult.Results }); }
/// <summary> /// Maps BllTestResult entity to DalTestResult entity. /// </summary> /// <param name="testResult"> BllTestResult instance.</param> /// <returns> DalTestResult instance.</returns> public static DalTestResult ToDalTestResult(this BllTestResult testResult) { return(new DalTestResult() { Id = testResult.Id, Grade = testResult.Grade, DateTime = testResult.DateTime, TimeSpent = testResult.TimeSpent, Test = testResult?.Test.ToDalTest(), User = (new BllUser { Id = testResult.UserId }).ToDalUser() }); }
public static PassedTestResult ToMvcPassedTestResult(this BllTestResult bllTestResult) { if (bllTestResult == null) { return(null); } return(new PassedTestResult() { Id = bllTestResult.Id, TestId = bllTestResult.TestId, UserId = bllTestResult.UserId, Runtime = bllTestResult.Runtime, IsSuccess = bllTestResult.IsSuccess, DateComplete = bllTestResult.DateComplete, Results = bllTestResult.Results.ToList() }); }
public static BllTestResult ToBllTestResult(this DalTestResult dalTestResult) { if (dalTestResult == null) { return(null); } var bllTestResult = new BllTestResult() { Id = dalTestResult.Id, TestId = dalTestResult.TestId, UserId = dalTestResult.UserId, Runtime = dalTestResult.Runtime, DateComplete = dalTestResult.DateComplete, IsSuccess = dalTestResult.IsSuccess, Results = dalTestResult.Results }; return(bllTestResult); }
public static DalTestResult ToDalTestResult(this BllTestResult bllTestResult) { if (bllTestResult == null) { return(null); } var dalTestResult = new DalTestResult() { Id = bllTestResult.Id, TestId = bllTestResult.TestId, UserId = bllTestResult.UserId, Runtime = bllTestResult.Runtime, DateComplete = bllTestResult.DateComplete, IsSuccess = bllTestResult.IsSuccess, Results = bllTestResult.Results }; return(dalTestResult); }
/// <summary> /// Evaluates test completed by user. /// </summary> /// <param name="completedTest"> Test completed by user.</param> /// <returns> TestResult instance.</returns> /// <exception> System.ArgumentNullException if completedTest is null.</exception> public BllTestResult EvaluateTest(BllCompletedTest completedTest) { if (completedTest == null) { throw new ArgumentNullException(nameof(completedTest)); } int numberOfCorrectAnswers = 0; foreach (var question in completedTest.Test.Questions) { int count = 0; foreach (var answer in question.CorrectAnswers) { if (completedTest.ChoosenAnswers.Select(a => a.Id).Contains(answer.Id)) { count++; } } if (count == question.CorrectAnswers.Count()) { numberOfCorrectAnswers++; } } var testResult = new BllTestResult { DateTime = DateTime.Now, Grade = GradeTest(numberOfCorrectAnswers, completedTest.Test.Questions.Count), TimeSpent = completedTest.TimeSpent, UserId = completedTest.UserId, Test = completedTest.Test }; repository.Create(testResult.ToDalTestResult()); service.Save(); return(testResult); }
/// <summary> /// 删除 /// </summary> public JsonResult SubmitTest(string id) { var json = new ModJsonResult(); try { int RightNum = Convert.ToInt32(Request["RightNum"] == null ? "" : Request["RightNum"]); var lmid = (Request["lmid"] == null ? "" : Request["lmid"]); var session = Session["ss"]; var uu = Session["uu"]; var gg = Session["gg"]; /*string url2 = HttpContext.Request.Url.Query; url2 = url2.Replace("?", ""); string[] urlpa = url2.Split('&'); int co = 0; string session = ""; foreach (string s in urlpa) { string[] val = s.Split('='); string co2=val[co]; if (co2=="sid"){ session = val[co + 1]; } }*/ BllTestResult bll = new BllTestResult(); ModTestResult model = new ModTestResult(); model.uid = uu.ToString(); model.qid = lmid; model.score = RightNum.ToString(); model.date = session.ToString(); float d = (float)RightNum / 100; int result = bll.Insert(model); String cc2 = "http://adapt2.sis.pitt.edu/cbum/um?app=37&act=" + model.qid + "&sub=" + lmid + "_test" + "&grp=" + gg + "&usr="******"&sid=" + model.date + "&res="+ d +"&svc=" + "m"; Process ps = new Process(); Process.Start(cc2); // HttpWebResponse rs = (HttpWebResponse)HttpWebRequest.Create(cc2.ToString()).GetResponse(); // Response.Write("<script language='javascript'>window.open('" + cc2 + "');</script>"); if (result>0) { json.success =true; } else { json.success = false; json.msg = " Failed!"; } } catch (Exception ex) { json.success = false; json.msg = "Error:" + ex.Message; } return Json(json, JsonRequestBehavior.AllowGet); }
/// <summary> /// Updates test results /// </summary> /// <param name="item"> Test result</param> public void Update(BllTestResult item) { throw new NotImplementedException(); }
/// <summary> /// Deletes test results /// </summary> /// <param name="entity">Test result</param> public void Delete(BllTestResult entity) { testResultRepository.Delete(entity.ToDalTestResult()); unitOfWork.Commit(); }