12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using Avalonia.Controls;
- using DatabaseMVVMApp.Models;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using Tmds.DBus.Protocol;
- namespace DatabaseMVVMApp.ViewModels
- {
- public class AddCourseViewModel : ReactiveObject
- {
- Course? _newCourse;
- string _errorText;
- bool _errorVisibility;
- UserControl _teacherControl;
- int? _duration;
- public int? Duration
- {
- get => _duration;
- set => this.RaiseAndSetIfChanged(ref _duration, value);
- }
- public UserControl TeacherControl
- {
- get => _teacherControl;
- set => this.RaiseAndSetIfChanged(ref _teacherControl, value);
- }
- public Course? NewCourse
- {
- get => _newCourse;
- set => this.RaiseAndSetIfChanged(ref _newCourse, value);
- }
- public AddCourseViewModel()
- {
- _newCourse = new Course();
- TeacherControl = new AddTeacher();
- }
- public AddCourseViewModel(UserControl control)
- {
- _newCourse = new Course();
- TeacherControl = control;
- }
- public string ErrorText
- {
- get => _errorText;
- set => this.RaiseAndSetIfChanged(ref _errorText, value);
- }
- public bool ErrorVisibility
- {
- get => _errorVisibility;
- set => this.RaiseAndSetIfChanged(ref _errorVisibility, value);
- }
- public void ToAddTeacherPage()
- {
- MainWindowViewModel.Instance.Control = TeacherControl;
- }
- public void AddCourse()
- {
- if (NewCourse.Title == null || NewCourse.Title == "")
- {
- ErrorText = "Ó íîâîãî êóðñà äîëæíî áûòü íàçâàíèå";
- ErrorVisibility = true;
- }
- else if (Duration == null)
- {
- ErrorText = "Ââåäåíà íåêîððåêòíàÿ ïðîäîëæèòåëüíîñòü";
- ErrorVisibility = true;
- }
- else
- {
- ErrorVisibility = false;
- MainWindowViewModel.connection.Courses.Add(NewCourse);
- string message = "Íîâûé êóðñ óñïåøíî äîáàâëåí";
- MainWindowViewModel.connection.SaveChanges();
- MainWindowViewModel.Instance.AddTeacherVM.AddCourse(NewCourse, Duration);
- MainWindowViewModel.Instance.Control = TeacherControl;
- MainWindowViewModel.MakeNotification(message);
- }
- }
- }
- }
|