コード例 #1
0
        public ActionResult WordsForLesson(string courseId, string lessonName, string token, string filter = "", bool sByMeaning = true, bool ascending = true)
        {
            if (AuthLogic.CheckToken(token) == "")
            {
                throw new Exception("NotAuthorized");
            }
            ViewData["token"]      = token;
            ViewData["courseId"]   = courseId;
            ViewData["lessonName"] = lessonName;

            // Za prvu ruku sve ide iz baze, poslije æu uzimati samo one koji odgovaraju
            // zadanom filtru
            var allWords = Word.GetAllWords();

            // filter
            ViewData["filter"] = filter;
            if (filter != null && filter != "")
            {
                allWords = allWords.Where(w => w.ModelWord.Meaning.ToLower().Contains(filter.ToLower()) ||
                                          w.ModelWord.Kana.ToLower().Contains(filter.ToLower()) ||
                                          w.ModelWord.Kanji.ToLower().Contains(filter.ToLower()) ||
                                          w.ModelWord.Level.ToLower().Contains(filter.ToLower())).ToList();
            }

            // sort
            ViewData["ascending"] = ascending;
            if (sByMeaning)
            {
                if (ascending)
                {
                    allWords = allWords.OrderBy(w => w.ModelWord.Meaning).ToList();
                }
                else
                {
                    allWords = allWords.OrderByDescending(w => w.ModelWord.Meaning).ToList();
                }
            }
            else
            {
                if (ascending)
                {
                    allWords = allWords.OrderBy(w => w.ModelWord.Level).ToList();
                }
                else
                {
                    allWords = allWords.OrderByDescending(w => w.ModelWord.Level).ToList();
                }
            }

            // paging

            var words = new List <WordView>();

            words = WordView.CastFromBllWord(allWords);
            return(View(words));
        }
コード例 #2
0
        // GET: Word
        public ActionResult Index(string token = "", string filter = "", bool sByMeaning = true, bool ascending = true)
        {
            if (token != "")
            {
                ViewData["token"] = token;
            }

            // Za prvu ruku sve ide iz baze, poslije æu uzimati samo one koji odgovaraju
            // zadanom filtru
            var allWords = Word.GetAllWords();

            // filter
            ViewData["filter"] = filter;
            if (filter != null && filter != "")
            {
                allWords = allWords.Where(w => w.ModelWord.Meaning.ToLower().Contains(filter.ToLower()) ||
                                          w.ModelWord.Kana.ToLower().Contains(filter.ToLower()) ||
                                          w.ModelWord.Kanji.ToLower().Contains(filter.ToLower()) ||
                                          w.ModelWord.Level.ToLower().Contains(filter.ToLower())).ToList();
            }

            // sort
            ViewData["ascending"] = ascending;
            if (sByMeaning)
            {
                if (ascending)
                {
                    allWords = allWords.OrderBy(w => w.ModelWord.Meaning).ToList();
                }
                else
                {
                    allWords = allWords.OrderByDescending(w => w.ModelWord.Meaning).ToList();
                }
            }
            else
            {
                if (ascending)
                {
                    allWords = allWords.OrderBy(w => w.ModelWord.Level).ToList();
                }
                else
                {
                    allWords = allWords.OrderByDescending(w => w.ModelWord.Level).ToList();
                }
            }

            // paging

            var words = new List <WordView>();

            words = WordView.CastFromBllWord(allWords);
            return(View(words));
        }