123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using ReactiveUI;
- using System.Linq;
- using System.Data;
- using AvaloniaApplication5.Models;
- using Microsoft.EntityFrameworkCore;
- using MsBox.Avalonia;
- using MsBox.Avalonia.Enums;
- namespace AvaloniaApplication5.ViewModels
- {
- public class AddDisCursViewModel : ViewModelBase
- {
- Course? _newcourse;
- public Course? NewCourse { get => _newcourse; set => this.RaiseAndSetIfChanged(ref _newcourse, value); }
- public List<Course> CoursesList => MainWindowViewModel.myConnection.Courses.ToList();
- public AddDisCursViewModel()
- {
- _newcourse = new Course();
- }
- string _message = "";
- public string Message
- {
- get => _message;
- set => this.RaiseAndSetIfChanged(ref _message, value);
- }
-
- public async void AddCourse()
- {
-
- if(string.IsNullOrEmpty(NewCourse.Time) || !IsNumeric(NewCourse.Time))
- {
- await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", " ïîëå êîëè÷åñòâà ÷àñîâ äîëæíû áûòü òîëüêî öèôðû").ShowAsync();
- return;
- }
- else
- {
- if (NewCourse.Id == 0)
- {
- MainWindowViewModel.myConnection.Courses.Add(NewCourse);
- }
- MainWindowViewModel.myConnection.SaveChanges();
- MainWindowViewModel.Instance.PageContent = new AddPage();
- }
-
- }
- private bool IsNumeric(string value)
- {
- return int.TryParse(value, out _); // Èëè double.TryParse, åñëè íóæíî ïîääåðæèâàòü äðîáíûå ÷èñëà
- }
- }
- }
|