AddCourseViewModel.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using ReactiveUI;
  4. using TeacheresAndCourses.Models;
  5. namespace TeacheresAndCourses.ViewModels
  6. {
  7. internal class AddCourseViewModel : ViewModelBase
  8. {
  9. Course? newCourse;
  10. string courseTitle;
  11. int courseHours;
  12. public AddCourseViewModel()
  13. {
  14. newCourse = new Course();
  15. }
  16. public Course NewCourse { get => newCourse; set => this.RaiseAndSetIfChanged(ref newCourse, value); }
  17. public string CourseTitle { get => courseTitle; set => this.RaiseAndSetIfChanged(ref courseTitle, value); }
  18. public int CourseHours { get => courseHours; set => this.RaiseAndSetIfChanged(ref courseHours, value); }
  19. public void AddCourse()
  20. {
  21. if (CourseTitle!=null && CourseHours!=null)
  22. {
  23. NewCourse.Title = CourseTitle + " - " + courseHours + " ÷àñîâ";
  24. }
  25. MainWindowViewModel.connection.Courses.Add(NewCourse);
  26. MainWindowViewModel.connection.SaveChanges();
  27. MainWindowViewModel.Instance.Uc = new AddTeacher();
  28. }
  29. public void ToMainPage()
  30. {
  31. MainWindowViewModel.Instance.Uc = new TeachersPage();
  32. }
  33. }
  34. }