public JsonResult TestStatictics() { string language = HttpContext.Session.GetString("lang"); var lang_id = from s in db.Languages where s.Name.ToString() == language select s.Id; int[] lgid = lang_id.ToArray(); string native_lang = HttpContext.Session.GetString("native_lang"); var native_lang_id = from s in db.Languages where s.Name.ToString() == native_lang select s.Id; int[] ntv_lgid = native_lang_id.ToArray(); CategoriesDTOsRepository categoryDTOs = new CategoriesDTOsRepository(); List <CategoriesDTO> CatDTO = categoryDTOs.GetCategoriesDTOs(ntv_lgid[0], lgid[0]).ToList(); TestsDTOsRepository TestDTOs = new TestsDTOsRepository(); List <CategoriesDTO> TestDTO = TestDTOs.GetTestDTOs(ntv_lgid[0], lgid[0]).ToList(); LanguagesDTOsRepository LangDTOs = new LanguagesDTOsRepository(); List <CategoriesDTO> LangDTO = LangDTOs.GetLanguagesDTOs(ntv_lgid[0], lgid[0]).ToList(); TestResultsRepository testResultRepository = new TestResultsRepository(); List <TestResults> testResult = testResultRepository.GetList().ToList(); TotalScoresRepository totalRepository = new TotalScoresRepository(); List <TotalScores> totalScore = totalRepository.GetList().ToList(); StatisticObject statisticObject = new StatisticObject(); statisticObject.CategoriesDTO = CatDTO; statisticObject.LanguageDTO = LangDTO; statisticObject.TestsDTO = TestDTO; statisticObject.TestResults = testResult; statisticObject.TotalScore = totalScore; return(Json(statisticObject)); }
public ActionResult GetTestResult(int score, int icon, int lang_id, int cat_id) { int catId = cat_id; int langId = lang_id; int TestIcon = icon; if (TestIcon == 0) { TestIcon = 10; } ; int Testscore = score; string strCurrentUserId = User.Identity.GetUserId(); int PrevScore; int IdPrevScore; DateTime currentData = DateTime.Now; TestResults testResult = new TestResults(); TestResultsRepository testResultRepos = new TestResultsRepository(); var ListTestresults = db.TestResults.Where(x => x.UserId == strCurrentUserId && x.TestId == TestIcon && x.LangId == langId && x.CategoryId == catId).ToList(); if (ListTestresults.Count != 0) { PrevScore = ListTestresults[0].Result; IdPrevScore = ListTestresults[0].Id; if (PrevScore < Testscore) { ListTestresults[0].Result = Testscore; ListTestresults[0].TestDate = currentData; db.SaveChanges(); var ListTotalScore = db.TotalScores.Where(x => x.UserId == strCurrentUserId).ToList(); ListTotalScore[0].Total = Testscore; db.SaveChanges(); } } if (ListTestresults.Count == 0) { db.TestResults.Add(new TestResults { TestId = TestIcon, TestDate = currentData, Result = Testscore, UserId = strCurrentUserId, CategoryId = catId, LangId = langId }); db.SaveChanges(); } var ListTotalTestresults = db.TestResults.Where(x => x.UserId == strCurrentUserId && x.LangId == langId).ToList(); if ((ListTotalTestresults.Count == 1) && (ListTestresults.Count == 0)) { db.TotalScores.Add(new TotalScores { UserId = strCurrentUserId, LangId = langId, Total = Testscore }); db.SaveChanges(); } if (ListTotalTestresults.Count > 1) { int TotalScore = 0; var ListTotalScore = db.TotalScores.Where(x => x.UserId == strCurrentUserId && x.LangId == langId).ToList(); foreach (var item in ListTotalTestresults) { TotalScore = TotalScore + item.Result; } ListTotalScore[0].Total = TotalScore; db.SaveChanges(); } return(View("_Close")); }