Przeglądaj źródła

Добавлено добавление, редактирование и удаление

AnnaBezaeva 2 tygodni temu
rodzic
commit
d6508278a0

+ 10 - 0
AvaloniaApplication5/ViewModels/AddPageViewModel.cs

@@ -22,12 +22,22 @@ namespace AvaloniaApplication5.ViewModels
 			{
 				Gender = new Gender() 
 			};
+            TextButton = "Äîáàâèòü";
+        }
+	   string text_button = "";
+		public string TextButton
+		{
+			get {  return text_button; }
+			set { this.RaiseAndSetIfChanged(ref text_button, value); }
 		}
 		public AddPageViewModel(int idt)
 		{
 			_newTeacher = MainWindowViewModel.myConnection.Teachers.Include(x=>x.Gender).Include(x=>x.TeacherCourses).ThenInclude(x=>x.Course).Include(x=>x.TeacherDisciplines).ThenInclude(x=>x.Discipline).FirstOrDefault(x=>x.Id == idt);
             TeacherCourses = NewTeacher.TeacherCourses.ToList();
 			TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
+			
+				TextButton = "Ðåäàêòèðîâàòü";
+			
 		}
 	    public List<Gender> Genders => MainWindowViewModel.myConnection.Genders.ToList();
 	    public List<Discipline> Disciplines => MainWindowViewModel.myConnection.Disciplines.ToList().Except(_newTeacher.TeacherDisciplines.Select(x =>x.Discipline)).ToList();

+ 13 - 1
AvaloniaApplication5/ViewModels/ShowViewModel.cs

@@ -5,6 +5,7 @@ using ReactiveUI;
 using System.Linq;
 using AvaloniaApplication5.Models;
 using Microsoft.EntityFrameworkCore;
+
 namespace AvaloniaApplication5.ViewModels
 {
     internal class ShowViewModel : ViewModelBase
@@ -18,6 +19,17 @@ namespace AvaloniaApplication5.ViewModels
         {
             MainWindowViewModel.Instance.PageContent = new AddPage();
         }
-     
+        public void DeleteTeacher(int idt)
+        {
+            Teacher deleteTeacher = MainWindowViewModel.myConnection.Teachers.First(x => x.Id == idt);
+        MainWindowViewModel.myConnection.Teachers.Remove(deleteTeacher);
+            MainWindowViewModel.myConnection.SaveChanges();
+            MainWindowViewModel.Instance.PageContent = new Show();
+        }
+        public void UpdateTeacher(int idt)
+        {
+           
+            MainWindowViewModel.Instance.PageContent = new AddPage(idt);
+        }
     }
 }

+ 7 - 7
AvaloniaApplication5/Views/AddPage.axaml

@@ -19,12 +19,12 @@
 			
 			<StackPanel  HorizontalAlignment="Center" >
 				<TextBlock FontWeight="Bold" Margin="40 20 0 0">Редактор</TextBlock>
-				<TextBox Watermark="Фамилия" Width="300" Margin="0 10 0 0"></TextBox>
-				<TextBox Watermark="Имя" Width="300" Margin="0 10 0 0"></TextBox>
-				<TextBox Watermark="Отчество" Width="300" Margin="0 10 0 0"></TextBox>
-				<TextBox Watermark="Почта" Width="300" Margin="0 10 0 0"></TextBox>
-				<TextBox Watermark="Телефон" Width="300" Margin="0 10 0 0"></TextBox>
-				<TextBox Watermark="Стаж" Width="300" Margin="0 10 0 0"></TextBox>
+				<TextBox Watermark="Фамилия" Width="300" Margin="0 10 0 0" Text="{Binding NewTeacher.LastName}"></TextBox>
+				<TextBox Watermark="Имя" Width="300" Margin="0 10 0 0" Text="{Binding NewTeacher.FirstName}"></TextBox>
+				<TextBox Watermark="Отчество" Width="300" Margin="0 10 0 0" Text="{Binding NewTeacher.PatronymicName}"></TextBox>
+				<TextBox Watermark="Почта" Width="300" Margin="0 10 0 0" Text="{Binding NewTeacher.Email}"></TextBox>
+				<TextBox Watermark="Телефон" Width="300" Margin="0 10 0 0" Text="{Binding NewTeacher.Phone}"></TextBox>
+				<TextBox Watermark="Стаж" Width="300" Margin="0 10 0 0" Text="{Binding NewTeacher.Experience}"></TextBox>
 				<DatePicker SelectedDate="{Binding NewTeacher.DateOfBirth, Converter={StaticResource myConverter}} "></DatePicker>
 				<ComboBox PlaceholderText="Выберите пол" ItemsSource="{Binding Genders}" Width="300" Margin="0 10 0 0" SelectedItem="{Binding NewTeacher.Gender}">
 					<ComboBox.ItemTemplate>
@@ -72,7 +72,7 @@
 						</DataTemplate>
 					</ListBox.ItemTemplate>
 				</ListBox>
-				<Button Command="{Binding AddTeacher}">Добавить</Button>
+				<Button Command="{Binding AddTeacher}" Content="{Binding TextButton}"></Button>
 
 			</StackPanel>
 				</Border>

+ 1 - 1
AvaloniaApplication5/Views/AddPage.axaml.cs

@@ -14,6 +14,6 @@ public partial class AddPage : UserControl
     public AddPage(int idt)
     {
         InitializeComponent();
-        DataContext = new AddPageViewModel();
+        DataContext = new AddPageViewModel(idt);
     }
 }

+ 4 - 1
AvaloniaApplication5/Views/Show.axaml

@@ -75,7 +75,10 @@
 									</ItemsRepeater.ItemTemplate>
 								</ItemsRepeater>
 							</StackPanel>
-					</StackPanel>
+							<Button Command="{Binding $parent[UserControl].((vm:ShowViewModel)DataContext).DeleteTeacher}" CommandParameter="{Binding Id}">Удалить</Button>
+							<Button Command="{Binding $parent[UserControl].((vm:ShowViewModel)DataContext).UpdateTeacher}" CommandParameter="{Binding Id}">Редактировать</Button>
+
+						</StackPanel>
 					</Border>
 				</DataTemplate>
 			</ListBox.ItemTemplate>