private async void handleClickAddGrade(object sender, RoutedEventArgs e) { Module module = (Module)((Button)sender).DataContext; var gradeDialog = new GradeDialog(new Grade(), module.id, GradeDialog.GradeDialogMode.CREATE); var buttonClicked = await gradeDialog.ShowAsync(); module.grades.Add(gradeDialog.result); if (buttonClicked == ContentDialogResult.Primary) { this.learningUnit = await PsApi.getInstance().getLearningUnitAsync(this.learningUnit.id); this.modules.Clear(); this.learningUnit.modules.ForEach(modules.Add); } }
private async void handleClickUpdateGrade(object sender, RoutedEventArgs e) { Grade grade = (Grade)((Button)sender).DataContext; var gradeDialog = new GradeDialog(grade, grade.id, GradeDialog.GradeDialogMode.EDIT); var buttonClicked = await gradeDialog.ShowAsync(); if (buttonClicked == ContentDialogResult.Primary) { Module module = modules.FirstOrDefault(m => m.grades.Select(g => grade.id).Contains(grade.id)); grade.name = gradeDialog.result.name; grade.coefficient = gradeDialog.result.coefficient; grade.score = gradeDialog.result.score; module.grades.Remove(grade); module.grades.Add(grade); var index = this.modules.IndexOf(module); modules.RemoveAt(index); modules.Insert(index, module); } }