Explorar el Código

7 работа готовая

ГаряевСА hace 2 semanas
padre
commit
30df87e961

+ 20 - 2
Teachers/ViewModels/AddCourseVM.cs

@@ -1,12 +1,30 @@
-using System;
+using ReactiveUI;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using Teachers.Models;
 
 namespace Teachers.ViewModels
 {
-    internal class AddCourseVM
+    internal class AddCourseVM : ViewModelBase
     {
+        Course? _newCourse;
+
+        public Course? NewCourse { get => _newCourse; set => this.RaiseAndSetIfChanged(ref _newCourse, value); }
+
+        public AddCourseVM()
+        {
+            _newCourse = new Course();
+        }
+
+        public void AddCourse()
+        {           
+            MainWindowViewModel.myConnection.Courses.Add(NewCourse);
+            MainWindowViewModel.myConnection.SaveChanges();
+            MainWindowViewModel.Instance.PageContent = new OneTeacherV();
+        }
+
     }
 }

+ 1 - 1
Teachers/ViewModels/OneTeacherVM.cs

@@ -92,7 +92,7 @@ namespace Teachers.ViewModels
             this.RaisePropertyChanged(nameof(Courses));
         }
 
-        public async void AddCourseAsync()
+        public void AddCourse()
         {
             MainWindowViewModel.Instance.PageContent = new AddCourseV();
         }

+ 3 - 2
Teachers/Views/AddCourseV.axaml

@@ -9,11 +9,12 @@
 	<StackPanel Margin="10">
 		<StackPanel Margin="0,0,10,10">
 			<TextBlock>Название курса</TextBlock>
-			<TextBox Text=""></TextBox>
+			<TextBox Text="{Binding NewCourse.Title}"></TextBox>
 		</StackPanel>
 		<StackPanel Margin="0,0,10,10">
 			<TextBlock>Количество часов</TextBlock>
-			<TextBox Text=""></TextBox>
+			<TextBox Text="{Binding NewCourse.Hours}"></TextBox>
 		</StackPanel>
+		<Button Command="{Binding AddCourse}">Добавить курс</Button>
 	</StackPanel>
 </UserControl>

+ 1 - 1
Teachers/Views/OneTeacherV.axaml

@@ -88,7 +88,7 @@
 							</ComboBox>
 						</StackPanel>
 						<StackPanel>
-							<Button Command="{Binding AddCourseAsync}">Добавить курс</Button>
+							<Button Command="{Binding AddCourse}">Добавить курс</Button>
 						</StackPanel>
 						</StackPanel>
 						<TextBlock>Выбранные курсы</TextBlock>