Exemple #1
0
        public async Task <GrammarExercise> EditGrammarExerciseAsync(GrammarExercise grammarExercise)
        {
            var dbGrammarExercise = _mapper.Map <DbGrammarExercise>(grammarExercise);

            return(_mapper.Map <GrammarExercise>(
                       await _exerciseRepository.EditGrammarExerciseAsync(dbGrammarExercise)));
        }
 public GrammarChooseOneExerciseViewModel(GrammarExercise grammarExercise, ICommand nextCommand)
 {
     Exercise    = grammarExercise;
     NextCommand = nextCommand;
     Answers     = new List <string>();
     SetAnswersRandom(Answers, Exercise);
     Answer_Click = new RelayCommand <string>(CheckAnswer);
 }
        private void GrammarGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            GrammarExercise parameter;

            if (e.ClickedItem.GetType() == typeof(NewGrammarExercise))
            {
                parameter = new GrammarExercise
                {
                    TestId = ViewModel.Test.ID
                };
            }
            else
            {
                parameter = (GrammarExercise)e.ClickedItem;
            }
            NavigationService.Navigate(typeof(EditGrammarExercisePage), parameter);
        }
Exemple #4
0
        public async Task <bool> DeleteGrammarExerciseAsync(GrammarExercise grammarExercise)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("api/exercise"));

                HttpResponseMessage response = await client.DeleteAsync($"{BaseUrl}/api/exercise/grammar/{grammarExercise.Id}");

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        protected void SetAnswersRandom(List <string> answers, GrammarExercise exercise)
        {
            answers.Add(exercise.CorrectAnswer);
            answers.Add(exercise.WrongAnswer1);
            answers.Add(exercise.WrongAnswer2);
            answers.Add(exercise.WrongAnswer3);

            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;
            }
        }
Exemple #6
0
        public async Task <GrammarExercise> PutGrammarExerciseAsync(GrammarExercise grammarExercise)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("api/exercise"));

                HttpResponseMessage response = await client.PutAsJsonAsync("api/exercise/grammar", grammarExercise);

                if (response.IsSuccessStatusCode)
                {
                    var serializer = new DataContractJsonSerializer(typeof(GrammarExercise));
                    return(serializer.ReadObject(await response.Content.ReadAsStreamAsync()) as GrammarExercise);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #7
0
 public async Task <IActionResult> EditGrammarExerciseAsync([FromBody] GrammarExercise grammarExercise)
 {
     return(Ok(await _exerciseManager.EditGrammarExerciseAsync(grammarExercise)));
 }
Exemple #8
0
 public GrammarChooseOneExerciseView(GrammarExercise grammarExercise, ICommand nextCommand)
 {
     this.InitializeComponent();
     ViewModel   = new GrammarChooseOneExerciseViewModel(grammarExercise, nextCommand);
     DataContext = ViewModel;
 }