Преглед на файлове

Почти доделано 7

semen преди 2 седмици
родител
ревизия
8b315ccfbb

+ 1 - 0
Teachers/Teachers.csproj

@@ -21,6 +21,7 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
+    <PackageReference Include="MessageBox.Avalonia" Version="3.1.6" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 12 - 0
Teachers/ViewModels/AddCourseVM.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Teachers.ViewModels
+{
+    internal class AddCourseVM
+    {
+    }
+}

+ 8 - 0
Teachers/ViewModels/OneTeacherVM.cs

@@ -6,6 +6,8 @@ using System.Text;
 using System.Threading.Tasks;
 using Avalonia.Controls;
 using Microsoft.EntityFrameworkCore;
+using MsBox.Avalonia.Enums;
+using MsBox.Avalonia;
 using ReactiveUI;
 using Teachers.Models;
 
@@ -90,6 +92,12 @@ namespace Teachers.ViewModels
             this.RaisePropertyChanged(nameof(Courses));
         }
 
+        public async void AddCourseAsync()
+        {
+            MainWindowViewModel.Instance.PageContent = new AddCourseV();
+        }
+
+
         public void AddChangeTeacher()
         {
             if (NewTeacher.IdTeacher == 0)

+ 22 - 6
Teachers/ViewModels/ShowTeacherVM.cs

@@ -7,6 +7,9 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Teachers.Models;
+using Tmds.DBus.Protocol;
+using MsBox.Avalonia.Enums;
+using MsBox.Avalonia;
 
 namespace Teachers.ViewModels
 {
@@ -23,7 +26,7 @@ namespace Teachers.ViewModels
                                                                    .Include(x => x.Teachercourses).ThenInclude(x => x.Course)
                                                                    .Include(x => x.Teacherdisciplines).ThenInclude(x => x.Discipline).ToList();
         }
-            public void ToAddTeacher()
+        public void ToAddTeacher()
         {
             MainWindowViewModel.Instance.PageContent = new OneTeacherV();
         }
@@ -33,12 +36,25 @@ namespace Teachers.ViewModels
             MainWindowViewModel.Instance.PageContent = new OneTeacherV(idTeacher);
         }
 
-        public void DeleteTeacher(int idTeacher)
+        public async void DeleteTeacherAsync(int idTeacher)
         {
-            Teacher deleteTeacher = MainWindowViewModel.myConnection.Teachers.First(x => x.IdTeacher == idTeacher); // ищем объект в базе по переданному id
-            MainWindowViewModel.myConnection.Teachers.Remove(deleteTeacher); // удаляем объект из БД
-            MainWindowViewModel.myConnection.SaveChanges(); // сохраняем измекнения в БД
-            MainWindowViewModel.Instance.PageContent = new ShowTeacherV(); // перезагружаем страницу
+            ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Удаление", "Вы действительно хотите удалить этого преподователя?", ButtonEnum.YesNo).ShowAsync();
+
+            switch (result)
+            {
+                case ButtonResult.Yes:
+                    {
+                        Teacher deleteTeacher = MainWindowViewModel.myConnection.Teachers.First(x => x.IdTeacher == idTeacher); // ищем объект в базе по переданному id
+                        MainWindowViewModel.myConnection.Teachers.Remove(deleteTeacher); // удаляем объект из БД
+                        MainWindowViewModel.myConnection.SaveChanges(); // сохраняем измекнения в БД
+                        MainWindowViewModel.Instance.PageContent = new ShowTeacherV(); // перезагружаем страницу
+                        break;
+                    }
+                case ButtonResult.No:
+                    {                     
+                        break;
+                    }
+            }
         }
     }
 }

+ 19 - 0
Teachers/Views/AddCourseV.axaml

@@ -0,0 +1,19 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+                xmlns:vm="using:Teachers.ViewModels"
+			 mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+                x:DataType="vm:AddCourseVM"
+			 x:Class="Teachers.AddCourseV">
+	<StackPanel Margin="10">
+		<StackPanel Margin="0,0,10,10">
+			<TextBlock>Название курса</TextBlock>
+			<TextBox Text=""></TextBox>
+		</StackPanel>
+		<StackPanel Margin="0,0,10,10">
+			<TextBlock>Количество часов</TextBlock>
+			<TextBox Text=""></TextBox>
+		</StackPanel>
+	</StackPanel>
+</UserControl>

+ 15 - 0
Teachers/Views/AddCourseV.axaml.cs

@@ -0,0 +1,15 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Teachers.ViewModels;
+
+namespace Teachers;
+
+public partial class AddCourseV : UserControl
+{
+    public AddCourseV()
+    {
+        InitializeComponent();
+        DataContext = new AddCourseVM();
+    }
+}

+ 1 - 1
Teachers/Views/OneTeacherV.axaml

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

+ 1 - 1
Teachers/Views/ShowTeacherV.axaml

@@ -58,7 +58,7 @@
 								</ItemsRepeater>
 							</StackPanel>
 							<Button Command="{Binding $parent[UserControl].((vm:ShowTeacherVM)DataContext).ToUpdateTeacher}" CommandParameter="{Binding IdTeacher}">Изменить</Button>
-							<Button Command="{Binding $parent[UserControl].((vm:ShowTeacherVM)DataContext).DeleteTeacher}" CommandParameter="{Binding IdTeacher}">Удалить</Button>
+							<Button Command="{Binding $parent[UserControl].((vm:ShowTeacherVM)DataContext).DeleteTeacherAsync}" CommandParameter="{Binding IdTeacher}">Удалить</Button>
 						</StackPanel>
 						</StackPanel>
 					</Border>