Пример #1
0
        public async Task <VocabularyExercise> EditVocabularyExerciseAsync(VocabularyExercise vocabularyExercise)
        {
            var dbVocabularyExercise = _mapper.Map <DbVocabularyExercise>(vocabularyExercise);

            return(_mapper.Map <VocabularyExercise>(
                       await _exerciseRepository.EditVocabularyExerciseAsync(dbVocabularyExercise)));
        }
 public ChooseOneExerciseViewModel(VocabularyExercise vocabularyExercise, ICommand nextCommand)
 {
     Exercise    = vocabularyExercise;
     NextCommand = nextCommand;
     State       = ExerciseState.NotAnswered;
     SetExerciseType();
     Answers = new List <string>();
     SetAnswersRandom(Answers, Exercise, TranslatedExpression, _isKnownToLearnig);
     Answer_Click = new RelayCommand <string>(CheckAnswer);
 }
Пример #3
0
        public async Task ProcessExercisesAsync()
        {
            var service = new ExerciseService();

            VocabularyExercises = await service.GetVocabularyExercises(Test);

            if (VocabularyExercises.Count != 0)
            {
                CurrentExercise = VocabularyExercises[0];
            }
        }
Пример #4
0
        public PictureExerciseViewModel(VocabularyExercise vocabularyExercise, ICommand nextCommand)
        {
            Exercise    = vocabularyExercise;
            NextCommand = nextCommand;
            Answers     = new List <string>();
            SetAnswersRandom(Answers, Exercise, Exercise.CorrectAnswer, true);
            var    resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            string baseurl        = resourceLoader.GetString("BaseUri");

            PictureLocation = $"{baseurl}/api/pictures/{Exercise.Picture}";
            Answer_Click    = new RelayCommand <string>(CheckAnswer);
        }
Пример #5
0
        private void VocabularyGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            VocabularyExercise parameter;

            if (e.ClickedItem.GetType() == typeof(NewVocabularyExercise))
            {
                parameter = new VocabularyExercise
                {
                    TestID = ViewModel.Test.ID
                };
            }
            else
            {
                parameter = (VocabularyExercise)e.ClickedItem;
            }
            NavigationService.Navigate(typeof(EditVocabularyExercisePage), parameter);
        }
Пример #6
0
        private IExerciseView SetExerciseType(VocabularyExercise exercise)
        {
            Random random       = new Random();
            int    randomNumber = random.Next(exercise.Picture == null ? 2 : 3);
            var    nextCommand  = new RelayCommand(NextExercise);

            if (randomNumber == 0)
            {
                return(new ChooseOneExerciseView(exercise, nextCommand));
            }
            else if (randomNumber == 1)
            {
                return(new TranslationExerciseView(exercise, nextCommand));
            }
            else
            {
                return(new PictureExerciseView(exercise, nextCommand));
            }
        }
        protected void SetAnswersRandom(List <string> answers, VocabularyExercise exercise, string translatedExpression, bool isKnownToLearnig)
        {
            answers.Add(translatedExpression);
            answers.Add(isKnownToLearnig ? exercise.WrongAnswer1 : exercise.TranslatedWrongAnswer1);
            answers.Add(isKnownToLearnig ? exercise.WrongAnswer2 : exercise.TranslatedWrongAnswer2);
            answers.Add(isKnownToLearnig ? exercise.WrongAnswer3 : exercise.TranslatedWrongAnswer3);

            Random random = new Random();
            int    n      = answers.Count;

            while (n > 1)
            {
                n--;
                int    k     = random.Next(n + 1);
                string value = answers[k];
                answers[k] = answers[n];
                answers[n] = value;
            }
        }
Пример #8
0
        public async Task <VocabularyExercise> PutVocabularyExerciseAsync(VocabularyExercise vocabularyExercise)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("api/exercise"));

                HttpResponseMessage response = await client.PutAsJsonAsync("api/exercise/vocabulary", vocabularyExercise);

                if (response.IsSuccessStatusCode)
                {
                    var serializer = new DataContractJsonSerializer(typeof(VocabularyExercise));
                    return(serializer.ReadObject(await response.Content.ReadAsStreamAsync()) as VocabularyExercise);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #9
0
        public async Task <bool> DeleteVocabularyExerciseAsync(VocabularyExercise vocabularyExercise)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("api/exercise"));

                HttpResponseMessage response = await client
                                               .DeleteAsync($"{BaseUrl}/api/exercise/vocabulary/{vocabularyExercise.ID}");

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #10
0
 public PictureExerciseView(VocabularyExercise vocabularyExercise, ICommand nextCommand)
 {
     this.InitializeComponent();
     ViewModel   = new PictureExerciseViewModel(vocabularyExercise, nextCommand);
     DataContext = ViewModel;
 }
Пример #11
0
 public async Task <IActionResult> EditVocabularyExerciseAsync([FromBody] VocabularyExercise vocabularyExercise)
 {
     return(Ok(await _exerciseManager.EditVocabularyExerciseAsync(vocabularyExercise)));
 }
Пример #12
0
 public TranslationExerciseViewModel(VocabularyExercise vocabularyExercise, ICommand nextCommand)
 {
     Exercise    = vocabularyExercise;
     NextCommand = nextCommand;
     SetExerciseType();
 }