コード例 #1
0
        // GET: ChooseLanguage

        public ActionResult Index()
        {
            using (wordcontext = new WordsContext())
            {
                usercl = wordcontext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                List <Language>         languagesToChoose;
                List <LearningStrategy> strategiesToChoose = new List <LearningStrategy>();
                NormalLearningStrategy  s1 = new NormalLearningStrategy();
                NewWordsStrategy        s2 = new NewWordsStrategy();
                MediumLearningStrategy  s3 = new MediumLearningStrategy();
                strategiesToChoose.Add(s1);
                strategiesToChoose.Add(s2);
                strategiesToChoose.Add(s3);

                languagesToChoose  = wordcontext.Languages.Where((el) => el.id < 3).ToList();
                ViewBag.Strategies = strategiesToChoose;
                ViewBag.Languages  = languagesToChoose;

                return(View());
            }
        }
コード例 #2
0
        public JsonResult GetWords(String option)
        {
            object traning;

            wordContext = new WordsContext();
            LearningStrategy ls;

            usercl = wordContext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
            int learningStrategy = usercl.settings.numberOfWordsPerLearning;

            ls = new NormalLearningStrategy();

            switch (learningStrategy)
            {
            case 1:
                ls = new NormalLearningStrategy();
                break;

            case 2:
                ls = new NewWordsStrategy();
                break;

            default:
                break;
            }
            string           exerciseType;
            List <LearnUnit> learnUnits = new List <LearnUnit>();
            List <string>    listOfOption;
            Random           randomNumber = new Random();

            int languageName = usercl.settings.currentLangage.id;
            //take all words where level of knowledge (1-10) is smaller than 6
            IEnumerable <UserWord> wordsForLearn = new List <UserWord>();
            int numberOfLanguageWords            = wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).Count();

            if (wordsForLearn.Count() < ls.getSumOFWords())
            {
                wordsForLearn = wordsForLearn.Union <UserWord>(wordContext.UserWords
                                                               .Where(x => x.levelOfKnowledge < 3 && x.levelOfKnowledge > 0 &&
                                                                      x.word.foreignLanguage.id == languageName &&
                                                                      x.user.id == usercl.id).Take(ls.getBasicWords()));
            }
            if (wordsForLearn.Count() < ls.getSumOFWords())
            {
                wordsForLearn = wordsForLearn.Union <UserWord>(wordContext.UserWords
                                                               .Where(x => x.levelOfKnowledge >= 3 && x.levelOfKnowledge < 7 &&
                                                                      x.word.foreignLanguage.id == languageName &&
                                                                      x.user.id == usercl.id).Take(ls.getIntermediateWords()));
            }
            if (wordsForLearn.Count() < ls.getSumOFWords())
            {
                wordsForLearn = wordsForLearn.Union <UserWord>(wordContext.UserWords
                                                               .Where(x => x.levelOfKnowledge >= 7 && x.levelOfKnowledge < 9 &&
                                                                      x.word.foreignLanguage.id == languageName &&
                                                                      x.user.id == usercl.id).Take(ls.getUpperIntermediateWords()));
            }
            if (wordsForLearn.Count() < ls.getSumOFWords())
            {
                wordsForLearn = wordsForLearn.Union <UserWord>(wordContext.UserWords
                                                               .Where(x => x.levelOfKnowledge >= 9 &&
                                                                      x.word.foreignLanguage.id == languageName &&
                                                                      x.user.id == usercl.id).OrderBy(x => x.lastTimeAccesed).Take(ls.getMasterWords()));
            }

            if (wordsForLearn.Count() < ls.getSumOFWords())
            {
                wordsForLearn = wordsForLearn.Union <UserWord>(wordContext.UserWords
                                                               .Where(x => x.levelOfKnowledge == 0 && x.word.foreignLanguage.id == languageName &&
                                                                      x.user.id == usercl.id).Take(ls.getSumOFWords() - wordsForLearn.Count()));
            }

            foreach (UserWord singleWord in wordsForLearn)
            {
                listOfOption = new List <string>();


                switch (singleWord.levelOfKnowledge)
                {
                case 0:
                    listOfOption.Add(singleWord.word.foreignText);
                    exerciseType = LearningType.Learning.name;
                    break;

                case 1:
                    exerciseType = LearningType.Choose.name;
                    listOfOption.Add(singleWord.word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    break;

                case 2:
                case 3:
                case 4:
                    exerciseType = LearningType.Choose.name;
                    listOfOption.Add(singleWord.word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    break;

                case 5:
                case 6:
                    exerciseType = LearningType.Choose.name;
                    listOfOption.Add(singleWord.word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    listOfOption.Add(wordContext.UserWords.Where(x => x.word.foreignLanguage.id == languageName).ToList().ElementAt(randomNumber.Next(0, numberOfLanguageWords - 1)).word.foreignText);
                    break;

                case 7:
                case 8:
                    exerciseType = LearningType.Writing.name;
                    //http://creativyst.com/Doc/Articles/SoundEx1/SoundEx1.htm
                    break;

                case 9:
                case 10:
                    exerciseType = LearningType.Writing.name;
                    break;

                default:
                    throw new NotImplementedException();
                }
                listOfOption.Shuffle();
                learnUnits.Add(new LearnUnit(singleWord, listOfOption, exerciseType));
            }

            traning = learnUnits
                      .Select(a => new
            {
                WordID   = a.userWord.id,
                Word     = a.userWord.word.homeText,
                WordExt  = a.userWord.word.foreignText,
                Level    = a.userWord.levelOfKnowledge,
                Exercise = a.exerciseType,
                Options  = a.listOfOptions
            });

            return(Json(traning, JsonRequestBehavior.AllowGet));
        }