private void btnDownloadHomework_Click(object sender, RoutedEventArgs e) { try { if (this.dataGridLessons.SelectedIndex < 0) { MessageBox.Show("Не сте избрали урок"); } else if (this.dataGridLessons.SelectedItems.Count > 1) { MessageBox.Show("Трябва да изберете точно един урок"); } else if (!(this.dataGridLessons.SelectedItem as dynamic).HasHomework) { MessageBox.Show("Този урок няма домашно"); } else { int lessonId = int.Parse((this.dataGridLessons.SelectedItem as dynamic) .Id.ToString()); File homework = client.DownloadLessonHomework(lessonId); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = homework.Filename; if (saveFileDialog.ShowDialog() == true) { if (homework.Filename.EndsWith(".html")) { System.IO.File.WriteAllText(saveFileDialog.FileName, Encoding.UTF8.GetString(homework.Content), Encoding.UTF8); } else { System.IO.File.WriteAllBytes(saveFileDialog.FileName, homework.Content); } MessageBox.Show("Домашното беше изтеглено успешно"); } } } catch (Exception ex) { MessageBox.Show(Application.Current.Resources["defaultErrorMessage"].ToString(), "Грешка", MessageBoxButton.OK, MessageBoxImage.Error); } }