Browse Source

add adding data in database from Nadia's pages

AngelikaSuhareva 4 months ago
parent
commit
703a460abd

+ 6 - 44
ViewModels/AddEmployeesViewModel.cs

@@ -9,54 +9,16 @@ namespace Acosta.ViewModels
 {
 	public class AddEmployeesViewModel : ReactiveObject
 	{
-        SuharevaContext myConnection1;
-        Employee currentUser;
+        SuharevaContext myC;
+        Employee? currentUser;
 
-        private UserControl uce = new AddTradeNetworksView();
-        public UserControl UCE { get => uce; set => this.RaiseAndSetIfChanged(ref uce, value); }
-        /*      string f;
-              string i;
-              string o;
-              string phone;
-              string email;
-              int role;
-              string password;*/
-
-        public AddEmployeesViewModel(SuharevaContext myConnection)
-        {
-            this.myConnection1 = myConnection;
-            CurrentUser = new Employee();
-/*            CurrentUser.Surname = F;
-            CurrentUser.Name = I;
-            CurrentUser.Patronymic = O;
-            CurrentUser.Phonenumber = Phone;
-            CurrentUser.Email = Email;
-            CurrentUser.Password = Password;
-            CurrentUser.Role = Role;*/
-            myConnection.Add(currentUser);
-        }
-        public AddEmployeesViewModel(SuharevaContext myConnection, int userID)
+        public AddEmployeesViewModel(SuharevaContext myC)
         {
-            this.myConnection1 = myConnection;
+            this.myC = myC;
             CurrentUser = new Employee();
-            myConnection.Add(currentUser);
+            myC.Add(CurrentUser);
         }
 
-        public Employee CurrentUser { get => currentUser; set => currentUser = value; }
-
-        /*public string Phone { get => phone; set => phone = value; }
-        public string Email { get => email; set => email = value; }
-        public int Role { get => role; set => role = value; }
-        public string Password { get => password; set => password = value; }
-        public string F { get => f; set => f = value; }
-        public string I { get => i; set => i = value; }
-        public string O { get => o; set => o = value; }*/
-
-        public void SaveUser()
-        {
-            
-            myConnection1.SaveChanges();
-            UCE = new EmployeesView();
-        }
+        public Employee? CurrentUser { get => currentUser; set => currentUser = value; }
     }
 }

+ 6 - 7
ViewModels/AddOutletsViewModel.cs

@@ -7,17 +7,16 @@ namespace Acosta.ViewModels
 {
     public class AddOutletsViewModel : ReactiveObject
     {
-        SuharevaContext myConnection;
-        Outlet currentOutlet;
+        SuharevaContext myC;
+        Outlet? currentOutlet;
 
-        public AddOutletsViewModel(SuharevaContext myConnection)
+        public AddOutletsViewModel(SuharevaContext myC)
         {
-            this.myConnection = myConnection;
+            this.myC = myC;
             CurrentOutlet = new Outlet();
-            myConnection.Add(CurrentOutlet);
-
+            myC.Add(CurrentOutlet);
         }
 
-        public Outlet CurrentOutlet { get => currentOutlet; set => currentOutlet = value; }
+        public Outlet? CurrentOutlet { get => currentOutlet; set => currentOutlet = value; }
     }
 }

+ 7 - 16
ViewModels/AddTradeNetworksViewViewModel.cs

@@ -9,25 +9,16 @@ namespace Acosta.ViewModels
 {
 	public class AddTradeNetworksViewViewModel : ReactiveObject
 	{
-		SuharevaContext myConnection;
-		TradeNetwork currentTrade;
+        SuharevaContext myC;
+        TradeNetwork? currentTrade;
 
-        private UserControl uct = new AddTradeNetworksView();
-        public UserControl UCT { get => uct; set => this.RaiseAndSetIfChanged(ref uct, value); }
-
-        public AddTradeNetworksViewViewModel(SuharevaContext myConnection)
-		{
-            this.myConnection = myConnection;
+        public AddTradeNetworksViewViewModel(SuharevaContext myC)
+        {
+            this.myC = myC;
             CurrentTrade = new TradeNetwork();
-            myConnection.Add(CurrentTrade);
+            myC.Add(CurrentTrade);
         }
 
-        public TradeNetwork CurrentTrade { get => currentTrade; set => currentTrade = value; }
-
-        public void SaveNetwork()
-        {
-            myConnection.SaveChanges();
-            UCT = new TradeNetworksView();
-        }
+        public TradeNetwork? CurrentTrade { get => currentTrade; set => currentTrade = value; }
     }
 }

+ 20 - 9
ViewModels/MainWindowViewModel.cs

@@ -11,20 +11,22 @@ namespace Acosta.ViewModels
 {
     public class MainWindowViewModel : ViewModelBase
     {
-        public static SuharevaContext myConnection = new SuharevaContext();
-        public static SuharevaContext myConnection1 = new SuharevaContext();
+        static SuharevaContext myConnection = new SuharevaContext();
+        static SuharevaContext myConnection1 = new SuharevaContext();
+        static SuharevaContext myConnection2 = new SuharevaContext();
+        static SuharevaContext myConnection3 = new SuharevaContext();
 
         AuthorizationViewModel authorizationVM = new AuthorizationViewModel();
         public AuthorizationViewModel AuthorizationVM { get => authorizationVM; set => authorizationVM = value; }
 
-        AddTradeNetworksViewViewModel addTradeNetworksVM = new AddTradeNetworksViewViewModel(myConnection);
+        AddTradeNetworksViewViewModel addTradeNetworksVM = new AddTradeNetworksViewViewModel(myConnection2);
         public AddTradeNetworksViewViewModel AddTradeNetworksVM { get => addTradeNetworksVM; set => addTradeNetworksVM = value; }
 
         AddEmployeesViewModel addEmployeesVM = new AddEmployeesViewModel(myConnection1);
         public AddEmployeesViewModel AddEmployeesVM { get => addEmployeesVM; set => addEmployeesVM = value; }
 
 
-        AddOutletsViewModel outletVM = new AddOutletsViewModel(myConnection);
+        AddOutletsViewModel outletVM = new AddOutletsViewModel(myConnection3);
         public AddOutletsViewModel OutletVM { get => outletVM; set => outletVM = value; }
 
 
@@ -36,14 +38,23 @@ namespace Acosta.ViewModels
         public PersonalAccountViewModel PersonalAccountVM { get => personalAccountVM; set => personalAccountVM = value; }
 
 
+        public void SaveNetwork()
+        {
+            myConnection2.SaveChanges();
+            UC = new TradeNetworksView();
+        }
 
-        
+        public void SaveUser()
+        {
+            myConnection1.SaveChanges();
+            UC = new EmployeesView();
+        }
 
-        /*public void SaveData()
+        public void SaveOutlet()
         {
-            myConnection.SaveChanges();
-            UC = new PersonalAccountView();
-        }*/
+            myConnection3.SaveChanges();
+            UC = new OutletsView();
+        }
 
         public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); } 
         private UserControl uc = new AuthorizationView();

+ 1 - 1
Views/AddEmployeesView.axaml

@@ -262,7 +262,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="{Binding AddEmployeesVM.SaveUser}">
+			<Button Classes="BtSave" Command="{Binding SaveUser}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>

+ 1 - 1
Views/AddOutletsView.axaml

@@ -227,7 +227,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="{}">
+			<Button Classes="BtSave" Command="{Binding SaveOutlet}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>

+ 1 - 1
Views/AddTradeNetworksView.axaml

@@ -185,7 +185,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="{Binding AddTradeNetworksVM.SaveNetwork}">
+			<Button Classes="BtSave" Command="{Binding SaveNetwork}">
 				
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>