public IActionResult TestPage() { //Use for Titile in html ViewData["Title"] = "Начало теста"; //Use for head in page ViewBag.HeadPageText = "Начало теста"; int[] arrayOfNumbers = TempData["Temp"] as int[]; List <WordInEnglish> words = WordsInEnglishContext.GetAllIQueryableWithInclude(w => w.TranslationOfWords).ToList(); List <WordInEnglish> currentWords = new List <WordInEnglish>(); for (int i = 0; i < arrayOfNumbers.Length; i++) { currentWords.Add(words[arrayOfNumbers[i]]); } List <CreatedTestYourselfViewModel> mapped = Mapper.Map <List <WordInEnglish>, List <CreatedTestYourselfViewModel> >(currentWords); return(View(mapped)); }
//Index view with filters public IActionResult Index(long?stage, string nameOfWord, SortIndexHome sortOrder = SortIndexHome.WordInEnglishAsc) { //Get data from database IQueryable <StageOfMethod> stagesOfMethod = StageOfMethodContext.GetAllIQueryableWithInclude(); IQueryable <WordInEnglish> wordsInEnglish = WordsInEnglishContext.GetAllIQueryableWithInclude(w => w.StageOfMethod, w => w.TranslationOfWords); //Filer by StageOfMethod if (stage != null && stage != 0) { wordsInEnglish = wordsInEnglish.Where(w => w.StageOfMethodId == stage); } //Search word by eglish word or by his translations if (!String.IsNullOrEmpty(nameOfWord)) { if (!Regex.IsMatch(nameOfWord, @"\P{IsCyrillic}")) { wordsInEnglish = wordsInEnglish.Where(w => w.Name.Contains(nameOfWord)); } else { wordsInEnglish = wordsInEnglish.Where(w => w.Name.Contains(nameOfWord)); } } //Sorting by Name of word in english and by name of stage //TODO add to html this possibility switch (sortOrder) { case SortIndexHome.WordInEnglishAsc: wordsInEnglish = wordsInEnglish.OrderBy(w => w.Name); break; case SortIndexHome.WordInEnglishDesc: wordsInEnglish = wordsInEnglish.OrderByDescending(w => w.Name); break; case SortIndexHome.StageOfMethodAsc: wordsInEnglish = wordsInEnglish.OrderBy(w => w.StageOfMethod.Name); break; case SortIndexHome.StageOfMethodDesc: wordsInEnglish = wordsInEnglish.OrderByDescending(w => w.StageOfMethod.Name); break; } //Add sotr add filter with data from database to view model IndexHomeViewModel model = new IndexHomeViewModel { Sorting = new SortIndexHomeViewModel(sortOrder), Filters = new FilterIndexHomeViewModel(stagesOfMethod.ToList(), stage, nameOfWord), WordsInEnglish = wordsInEnglish }; return(View(model)); }