AddCourseView.axaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Interactivity;
  4. using Avalonia.Markup.Xaml;
  5. using System.Collections.Generic;
  6. using Teachers.Models;
  7. using Teachers.ViewModels;
  8. namespace Teachers;
  9. public partial class AddCourseView : UserControl
  10. {
  11. public AddCourseView()
  12. {
  13. InitializeComponent();
  14. DataContext = new AddTeacherViewModel();
  15. //if (bSaveCourse.IsPressed)
  16. }
  17. private void bAddCourse(object sender, RoutedEventArgs e)
  18. {
  19. //AddTeacherViewModel viewModel = new AddTeacherViewModel();
  20. //viewModel.AddCourse();
  21. AddCourse();
  22. var window = this.VisualRoot as Window;
  23. window?.Close();
  24. }
  25. public void AddCourse()
  26. {
  27. TeacherCourse tcToAdd = new TeacherCourse();
  28. tcToAdd.IdCourseNavigation = _newCourse;
  29. tcToAdd.IdTeacherNavigation = _newTeacher;
  30. //tcToAdd.IdCourse = _newCourse.Id;
  31. //tcToAdd.IdTeacher = _newTeacher.Id;
  32. List<TeacherCourse> tcToAddList = new List<TeacherCourse>();
  33. tcToAddList.Add(tcToAdd);
  34. //Course addCourse = new Course()
  35. //{
  36. // Name = _newCourse.Name,
  37. // Duration = _newCourse.Duration,
  38. // //TeacherCourses = tcToAddList,
  39. // //TeacherCourses = new TeacherCourse() { IdCourseNavigation = NewCourse, IdTeacherNavigation = NewTeacher },
  40. //};
  41. //MainWindowViewModel.myConnection.Courses.Add(NewCourse);
  42. //MainWindowViewModel.myConnection.Courses.Add(addCourse);
  43. //AddTeacherViewModel viewModel = new AddTeacherViewModel();
  44. //var a = viewModel._courseWindow;
  45. MainWindowViewModel.myConnection.Courses.Add(this.NewCourse);
  46. MainWindowViewModel.myConnection.SaveChanges();
  47. //window.Close();
  48. //rubilnik = false;
  49. //ShowAddCourse();
  50. //CloseWindow();
  51. }
  52. private void bAddCourse(object sender, RoutedEventArgs e)
  53. {
  54. AddCourse();
  55. var window = this.VisualRoot as Window;
  56. window?.Close();
  57. AddTeacherViewModel viewModel = new AddTeacherViewModel();
  58. viewModel.UpdateList();
  59. }
  60. public void AddCourse()
  61. {
  62. Course newCourse = new Course() { Name = tbCourse.Text, Duration = int.Parse(tbDuration.Text) };
  63. MainWindowViewModel.myConnection.Courses.Add(newCourse);
  64. MainWindowViewModel.myConnection.SaveChanges();
  65. }
  66. }