AddCourseView.axaml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Interactivity;
  4. using Avalonia.Markup.Xaml;
  5. using MsBox.Avalonia;
  6. using MsBox.Avalonia.Enums;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using Teachers.Models;
  10. using Teachers.ViewModels;
  11. namespace Teachers;
  12. public partial class AddCourseView : UserControl
  13. {
  14. public AddCourseView()
  15. {
  16. InitializeComponent();
  17. DataContext = new AddTeacherViewModel();
  18. }
  19. private async void bAddCourse(object sender, RoutedEventArgs e)
  20. {
  21. AddCourse();
  22. var window = this.VisualRoot as Window;
  23. ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Âíèìàíèå", "Ïðè äîáàâëåíèè êóðñà âñå çàïîëíåííûå ïîëÿ áóäóò î÷èùåíû. Âû óâåðåíû, ÷òî õîòèòå äîáàâèòü íîâûé êóðñ?", MsBox.Avalonia.Enums.ButtonEnum.YesNo).ShowAsync();
  24. switch (result)
  25. {
  26. case ButtonResult.Yes:
  27. {
  28. window?.Close();
  29. MainWindowViewModel.Instance.Us = new AddTeacherView();
  30. break;
  31. }
  32. case ButtonResult.No:
  33. {
  34. window?.Close();
  35. break;
  36. }
  37. }
  38. }
  39. public void AddCourse()
  40. {
  41. Course newCourse = new Course() { Name = tbCourse.Text, Duration = int.Parse(tbDuration.Text) };
  42. MainWindowViewModel.myConnection.Courses.Add(newCourse);
  43. MainWindowViewModel.myConnection.SaveChanges();
  44. }
  45. }