AddCourseVM.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using AvaloniaBaseTeacher.Models;
  2. using Microsoft.EntityFrameworkCore;
  3. using ReactiveUI;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace AvaloniaBaseTeacher.ViewModels
  10. {
  11. internal class AddCourseVM : ViewModelBase
  12. {
  13. Course _Newcourse;
  14. public Course Newcourse { get => _Newcourse; set => this.RaiseAndSetIfChanged(ref _Newcourse, value); }
  15. public AddCourseVM()
  16. {
  17. _Newcourse = new Course();
  18. }
  19. public AddCourseVM(int CourseId)
  20. {
  21. _Newcourse = MainWindowViewModel.myConnection.Courses.FirstOrDefault(x => x.IdCourse == CourseId);
  22. }
  23. public void AddCourse()
  24. {
  25. if(Newcourse.IdCourse == 0)
  26. {
  27. MainWindowViewModel.myConnection.Courses.Add(Newcourse);
  28. }
  29. MainWindowViewModel.myConnection.SaveChanges();
  30. MainWindowViewModel.Instance.PageContent = new Add();
  31. }
  32. }
  33. }