AngelikaSuhareva 4 miesięcy temu
rodzic
commit
2bc8a48f5d

+ 22 - 0
ViewModels/AddEmployeesViewModel.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using Acosta.Models;
+using ReactiveUI;
+
+namespace Acosta.ViewModels
+{
+	public class AddEmployeesViewModel : ReactiveObject
+	{
+        SuharevaContext myConnection;
+        Employee currentUser;
+
+        public AddEmployeesViewModel(SuharevaContext myConnection)
+        {
+            this.myConnection = myConnection;
+            CurrentUser = new Employee();
+            myConnection.Add(CurrentUser);  
+        }
+
+        public Employee CurrentUser { get => currentUser; set => currentUser = value; }
+    }
+}

+ 10 - 2
ViewModels/MainWindowViewModel.cs

@@ -17,14 +17,22 @@ namespace Acosta.ViewModels
         AddTradeNetworksViewViewModel addTradeNetworksVM = new AddTradeNetworksViewViewModel(myConnection);
         public AddTradeNetworksViewViewModel AddTradeNetworksVM { get => addTradeNetworksVM; set => addTradeNetworksVM = value; }
 
-        public void SaveData()
+        AddEmployeesViewModel addEmployeesViewModel = new AddEmployeesViewModel(myConnection);
+        public AddEmployeesViewModel AddEmployeesViewModel { get => addEmployeesViewModel; set => addEmployeesViewModel = value; }
+
+        public void SaveNetwork()
         {
             myConnection.SaveChanges();
             UC = new TradeNetworksView();
         }
 
-        public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }  
+        public void SaveUser()
+        {
+            myConnection.SaveChanges();
+            UC = new EmployeesView();
+        }
 
+        public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); } 
         private UserControl uc = new AddEmployeesView();
 
         public void LoadPersonalAccount()

+ 1 - 1
Views/AddEmployeesView.axaml

@@ -244,7 +244,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="">
+			<Button Classes="BtSave" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveUser}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>

+ 1 - 1
Views/AddTradeNetworksView.axaml

@@ -187,7 +187,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveData}">
+			<Button Classes="BtSave" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveNetwork}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>