123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Interactivity;
- using Avalonia.Markup.Xaml;
- using System.Collections.Generic;
- using Teachers.Models;
- using Teachers.ViewModels;
- namespace Teachers;
- public partial class AddCourseView : UserControl
- {
- public AddCourseView()
- {
- InitializeComponent();
- DataContext = new AddTeacherViewModel();
- //if (bSaveCourse.IsPressed)
- }
- private void bAddCourse(object sender, RoutedEventArgs e)
- {
- //AddTeacherViewModel viewModel = new AddTeacherViewModel();
- //viewModel.AddCourse();
- AddCourse();
- var window = this.VisualRoot as Window;
- window?.Close();
- }
- public void AddCourse()
- {
- TeacherCourse tcToAdd = new TeacherCourse();
- tcToAdd.IdCourseNavigation = _newCourse;
- tcToAdd.IdTeacherNavigation = _newTeacher;
- //tcToAdd.IdCourse = _newCourse.Id;
- //tcToAdd.IdTeacher = _newTeacher.Id;
- List<TeacherCourse> tcToAddList = new List<TeacherCourse>();
- tcToAddList.Add(tcToAdd);
- //Course addCourse = new Course()
- //{
- // Name = _newCourse.Name,
- // Duration = _newCourse.Duration,
- // //TeacherCourses = tcToAddList,
- // //TeacherCourses = new TeacherCourse() { IdCourseNavigation = NewCourse, IdTeacherNavigation = NewTeacher },
- //};
- //MainWindowViewModel.myConnection.Courses.Add(NewCourse);
- //MainWindowViewModel.myConnection.Courses.Add(addCourse);
- //AddTeacherViewModel viewModel = new AddTeacherViewModel();
- //var a = viewModel._courseWindow;
- MainWindowViewModel.myConnection.Courses.Add(this.NewCourse);
- MainWindowViewModel.myConnection.SaveChanges();
- //window.Close();
- //rubilnik = false;
- //ShowAddCourse();
- //CloseWindow();
- }
- private void bAddCourse(object sender, RoutedEventArgs e)
- {
- AddCourse();
- var window = this.VisualRoot as Window;
- window?.Close();
- AddTeacherViewModel viewModel = new AddTeacherViewModel();
- viewModel.UpdateList();
- }
- public void AddCourse()
- {
- Course newCourse = new Course() { Name = tbCourse.Text, Duration = int.Parse(tbDuration.Text) };
- MainWindowViewModel.myConnection.Courses.Add(newCourse);
- MainWindowViewModel.myConnection.SaveChanges();
- }
- }
|