Ejemplo n.º 1
0
        public ActionResult Index(int Level = 1, int Page = 1, string Result = "")
        {
            //Generate Words
            FlashCardListViewModel flashCardListViewModel = new FlashCardListViewModel();

            LoadIncluded(Level);
            flashCardListViewModel.Words = ToList(includedWords);

            //Insert Solution
            Word      question = flashCardListViewModel.Words.ElementAt(Page - 1);
            ArrayList answers  = new ArrayList();

            answers.Add(question);
            flashCardListViewModel.Answers = ToList(answers);

            //Select One for Show and Pagination
            flashCardListViewModel.Words = flashCardListViewModel.Words.OrderBy(w => w.Id).Skip((Page - 1)).Take(1);

            flashCardListViewModel.PagingPrevNext = new PagingPrevNext {
                CurrentPage = Page, TotalItems = flashCardListViewModel.Words.Count()
            };

            ViewBag.Result = Result;
            ViewBag.Level  = Level;

            return(View("Index", flashCardListViewModel));
        }
        public ActionResult Answer(IncludedIdioms included, string Question, int Page)
        {
            FlashCardListViewModel flashCardListViewModel = new FlashCardListViewModel();

            flashCardListViewModel.Words = included.Words;

            flashCardListViewModel.PagingPrevNext = new PagingPrevNext {
                CurrentPage = Page, TotalItems = flashCardListViewModel.Words.Count()
            };

            //Find Solution
            Word   word = flashCardListViewModel.Words.ElementAt(Page - 1);
            string URL  = "";


            //TRANSPARENCY ON LINE https://www194.lunapic.com/editor/
            if (Question == word.NumberPinyin)
            {
                Result = "Ok";
                URL    = "/IdiomsCardRandom/Index/" + "/" + (Page + 1).ToString() + "/Ok";
            }
            else
            {
                Result = "Wrong";
                URL    = "/IdiomsCardRandom/Index/" + "/" + (Page + 1).ToString() + "/Ko";
            }



            return(new RedirectResult(URL));
        }
        private void GenerateIdiomsAnswers(FlashCardListViewModel flashCardListViewModel, int Page)
        {
            Word question = flashCardListViewModel.Words.ElementAt(Page - 1);

            int FakeAnswers = 3;

            ArrayList answers = new ArrayList();

            Random r = new Random();

            //All but no the same as que question can be candidates to be a distractor
            List <Word> distractors = flashCardListViewModel.Words.Where(x => x.Character != question.Character).ToList();

            for (int i = 0; i < FakeAnswers; i++)
            {
                //Select one distractor
                int random = r.Next(0, distractors.Count);

                Word w = distractors[random];

                answers.Add(w);
            }

            //Añade la respuesta correcta en una posicion tambien aleatoria
            int RandomInsertion = r.Next(0, FakeAnswers - 1);

            answers.Insert(RandomInsertion, question);

            flashCardListViewModel.Answers = ToList(answers);
        }
        private void GenerateAnswers(FlashCardListViewModel flashCardListViewModel, int Page)
        {
            Word question = flashCardListViewModel.Words.ElementAt(Page - 1);

            int FakeAnswers = 3;

            ArrayList answers = new ArrayList();

            Random r = new Random();

            List <Word> sameCharacterLenghtWords = flashCardListViewModel.Words.Where(x => x.Character.Length == question.Character.Length).ToList();

            for (int i = 0; i < FakeAnswers; i++)
            {
                int random = r.Next(0, sameCharacterLenghtWords.Count);

                Word w = sameCharacterLenghtWords[random];

                answers.Add(w);
            }

            //Añade la respuesta correcta en una posicion tambien aleatoria
            int RandomInsertion = r.Next(0, FakeAnswers - 1);

            answers.Insert(RandomInsertion, question);

            flashCardListViewModel.Answers = ToList(answers);
        }
Ejemplo n.º 5
0
        public ActionResult Answer(int Level, string Question, int Page)
        {
            FlashCardListViewModel flashCardListViewModel = new FlashCardListViewModel();

            LoadIncluded(Level);

            flashCardListViewModel.Words = ToList(includedWords);

            flashCardListViewModel.PagingPrevNext = new PagingPrevNext {
                CurrentPage = Page, TotalItems = flashCardListViewModel.Words.Count()
            };

            string URL = "/FlashCard/Index/" + Level + "/" + (Page + 1).ToString();

            return(new RedirectResult(URL));
        }
        public ActionResult Index(IncludedIdioms includedIdioms, int Page = 1, string Result = "")
        {
            //Generate Words
            FlashCardListViewModel flashCardListViewModel = new FlashCardListViewModel();

            flashCardListViewModel.Words = includedIdioms.Words;

            GenerateIdiomsAnswers(flashCardListViewModel, Page);

            //Select One for Show and Pagination
            flashCardListViewModel.Words = flashCardListViewModel.Words.OrderBy(w => w.Id).Skip((Page - 1)).Take(1);

            flashCardListViewModel.PagingPrevNext = new PagingPrevNext {
                CurrentPage = Page, TotalItems = flashCardListViewModel.Words.Count()
            };

            ViewBag.Result = Result;


            return(View("Index", flashCardListViewModel));
        }