浏览代码

add editing for employees and outlets

AngelikaSuhareva 4 月之前
父节点
当前提交
2e326047ce

+ 7 - 0
ViewModels/AddEmployeesViewModel.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using Acosta.Models;
 using Acosta.Views;
 using Avalonia.Controls;
@@ -19,6 +20,12 @@ namespace Acosta.ViewModels
             myC.Add(CurrentUser);
         }
 
+        public AddEmployeesViewModel(SuharevaContext myC, int idUser)
+        {
+            this.myC = myC;
+            CurrentUser = myC.Employees.FirstOrDefault(x => x.Employeesid == idUser);
+        }
+
         public Employee? CurrentUser { get => currentUser; set => currentUser = value; }
     }
 }

+ 25 - 0
ViewModels/EditEmployeeViewModel.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Acosta.Models;
+using Acosta.Views;
+using Avalonia.Controls;
+using Microsoft.EntityFrameworkCore;
+using ReactiveUI;
+
+namespace Acosta.ViewModels
+{
+	public class EditEmployeeViewModel : ReactiveObject
+	{
+        SuharevaContext myC;
+        Employee? currentUser;
+
+        public EditEmployeeViewModel(SuharevaContext myC, int userId)
+        {
+            this.myC = myC;
+            currentUser = myC.Employees.Include(x => x.RoleNavigation).FirstOrDefault(x => x.Employeesid == userId);
+        }
+
+        public Employee? CurrentUser { get => currentUser; set => currentUser = value; }
+    }
+}

+ 25 - 0
ViewModels/EditOutletViewModel.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Acosta.Models;
+using Acosta.Views;
+using Avalonia.Controls;
+using Microsoft.EntityFrameworkCore;
+using ReactiveUI;
+
+namespace Acosta.ViewModels
+{
+	public class EditOutletViewModel : ReactiveObject
+	{
+        SuharevaContext myC;
+        Outlet? currentOutlet;
+
+        public EditOutletViewModel(SuharevaContext myC, int outletId)
+        {
+            this.myC = myC;
+            CurrentOutlet = myC.Outlets.Include(x => x.TradeNetworksNavigation).FirstOrDefault(x => x.Outletid == outletId);
+        }
+
+        public Outlet? CurrentOutlet { get => currentOutlet; set => currentOutlet = value; }
+    }
+}

+ 37 - 3
ViewModels/MainWindowViewModel.cs

@@ -18,6 +18,8 @@ namespace Acosta.ViewModels
         static SuharevaContext myConnection2 = new SuharevaContext();
         static SuharevaContext myConnection3 = new SuharevaContext();
         static SuharevaContext myConnection4 = new SuharevaContext();
+        static SuharevaContext myConnection5 = new SuharevaContext();
+        static SuharevaContext myConnection6 = new SuharevaContext();
 
         AuthorizationViewModel authorizationVM = new AuthorizationViewModel();
                
@@ -33,6 +35,12 @@ namespace Acosta.ViewModels
         AddOutletsViewModel outletVM = new AddOutletsViewModel(myConnection3);
         public AddOutletsViewModel OutletVM { get => outletVM; set => outletVM = value; }
 
+        EditEmployeeViewModel editUserVM;
+        public EditEmployeeViewModel EditUserVM { get => editUserVM; set => editUserVM = value; }
+
+        EditOutletViewModel editOutletVM;
+        public EditOutletViewModel EditOutletVM { get => editOutletVM; set => editOutletVM = value; }
+
         //OutletsListViewModel outletListVM = new OutletsListViewModel(myConnection);
         //public OutletsListViewModel OutletListVM { get => outletListVM; set => outletListVM = value; }
 
@@ -66,6 +74,30 @@ namespace Acosta.ViewModels
             UC = new VisitsView();
         }
 
+        public void SaveEditUser()
+        {
+            myConnection5.SaveChanges();
+            UC = new EmployeesView();
+        }
+
+        public void SaveEditOutlet()
+        {
+            myConnection6.SaveChanges();
+            UC = new OutletsView();
+        }
+
+        public void EditUser(int userId)
+        {
+            editUserVM = new EditEmployeeViewModel(myConnection5, userId);
+            UC = new EditEmployeesView();
+        }
+
+        public void EditOutlet(int outletId)
+        {
+            editOutletVM = new EditOutletViewModel(myConnection6, outletId);
+            UC = new EditOutletsView();
+        }
+
         public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); } 
         private UserControl uc = new AuthorizationView();
         public int curUsId;
@@ -93,20 +125,22 @@ namespace Acosta.ViewModels
 
         public List<Project> ListProjects => myConnection.Projects.ToList();
         public List<TradeNetwork> ListTrades => myConnection.TradeNetworks.ToList();
-        public List<Employee> ListEmployees => myConnection.Employees.ToList().Where(x => x.Employeesid != curUsId).ToList();
+        public List<Employee> ListEmployees => myConnection.Employees.Include(x => x.RoleNavigation).ToList().Where(x => x.Employeesid != curUsId).ToList();
         public List<Outlet> ListOutlets => myConnection.Outlets.ToList();
         public List<Visit> ListVisits => myConnection.Visits.ToList();
+
+
         //List<a> newList = new List<a>(new a((from p in myConnection.Outlets.ToList() select p.Outletid).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.Outlets.ToList() select p.Address).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.Outlets.ToList() select p.Location).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.TradeNetworks.ToList() select p.Title).ToImmutableList().ToList().FirstOrDefault()));
         //public List<string> fkTrade => myConnection.TradeNetworks.ToList().Select(x => x.Title).Where()
         //List<a> newList = new List<a>(new a((from p in myConnection.Outlets.ToList() select p.Outletid).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.Outlets.ToList() select p.Address).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.Outlets.ToList() select p.Location).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.TradeNetworks.ToList() select p.Title).ToImmutableList().ToList().FirstOrDefault()));
-        
+
         //public struct a
         //{
         //    int Outlerid;
         //    string Address;
         //    string Location;
         //    string TradeNetworks;
-            
+
 
         //    public a(int oid, string ad, string loc, string tn)
         //    {

+ 1 - 1
Views/AuthorizationView.axaml

@@ -30,7 +30,7 @@
 			<TextBox Text="{Binding AuthorizationVM.Password}" Watermark="Пароль" PasswordChar="•" Width="360"></TextBox>
 			<TextBlock Text="{Binding AuthorizationVM.Message}"/>
 			<TextBlock Margin="0 5 0 0" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="13" Foreground="#A52C2C"></TextBlock>
-			<Button HorizontalAlignment="Center" Margin="0 20 0 10" Width="230" Height="45" CornerRadius="10" Background="#E40714" Command="{Binding LoadPersonalAccount}">
+			<Button HorizontalAlignment="Center" Margin="0 20 0 10" Width="230" Height="45" CornerRadius="10" Background="#E40714" Command="{Binding LoadPersonalAccount}" IsDefault="True">
 				<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Roboto" FontSize="16" FontWeight="DemiBold" Foreground="White">Войти</TextBlock>
 			</Button>
 		</StackPanel>

+ 19 - 17
Views/EditEmployeesView.axaml

@@ -147,50 +147,52 @@
 			<StackPanel Orientation="Vertical">
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">ID:</TextBlock>
-					<TextBox Watermark="ID" Width="360" Margin="218 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.Employeesid}" Watermark="ID" Width="360" Margin="218 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Фамилия:</TextBlock>
-					<TextBox Watermark="Фималия" Width="360" Margin="160 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.Surname}" Watermark="Фималия" Width="360" Margin="160 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Имя:</TextBlock>
-					<TextBox Watermark="Имя" Width="360" Margin="200 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.Name}" Watermark="Имя" Width="360" Margin="200 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Отчетсво:</TextBlock>
-					<TextBox Watermark="Отчетсво" Width="360" Margin="156 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.Patronymic}" Watermark="Отчетсво" Width="360" Margin="156 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Почта:</TextBlock>
-					<TextBox Watermark="Почта" Width="360" Margin="185 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.Email}" Watermark="Почта" Width="360" Margin="185 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Телефон:</TextBlock>
-					<TextBox Watermark="Телефон" Width="360" Margin="165 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.Phonenumber}" Watermark="Телефон" Width="360" Margin="165 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Роль:</TextBlock>
-					<TextBox Watermark="Роль" Width="360" Margin="197 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditUserVM.CurrentUser.RoleNavigation.Title}" Watermark="Роль" Width="360" Margin="197 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Vertical">
 					<TextBlock Classes="TextToTextBox">Проекты:</TextBlock>
-					<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
-						<TextBlock>Проект “...”</TextBlock>
-					</CheckBox>
-					<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
-						<TextBlock>Проект “...”</TextBlock>
-					</CheckBox>
-					<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
-						<TextBlock>Проект “...”</TextBlock>
-					</CheckBox>				
+					<ListBox ItemsSource="{Binding ListProjects}">
+						<ListBox.ItemTemplate>
+							<DataTemplate>
+								<StackPanel Orientation="Vertical">
+									<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
+										<TextBlock Text="{Binding Title}"></TextBlock>
+									</CheckBox>
+								</StackPanel>
+							</DataTemplate>
+						</ListBox.ItemTemplate>
+					</ListBox>	
 				</StackPanel>
 			</StackPanel>
 			</ScrollViewer>
@@ -247,7 +249,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="">
+			<Button Classes="BtSave" Command="{Binding SaveEditUser}">
 				<TextBlock Classes="TextBtSave">Сохранить</TextBlock>
 			</Button>
 		</StackPanel>

+ 15 - 17
Views/EditOutletsView.axaml

@@ -152,34 +152,32 @@
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Торговая сеть:</TextBlock>
-					<ComboBox Classes="TextToComboBox" SelectedIndex="0" Margin="120 20 0 0" Width="360" Height="40">
-						<ComboBoxItem IsEnabled="False">–––––––––––––</ComboBoxItem>
-						<!--пример-->
-						<ComboBoxItem>Магнит</ComboBoxItem>
-					</ComboBox>
+					<TextBox Text="{Binding EditOutletVM.CurrentOutlet.TradeNetworksNavigation.Title}" Watermark="Торговая сеть" Width="360" Margin="185 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Адрес:</TextBlock>
-					<TextBox Watermark="Адрес" Width="360" Margin="185 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditOutletVM.CurrentOutlet.Address}" Watermark="Адрес" Width="360" Margin="185 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Местоположение:</TextBlock>
-					<TextBox Watermark="Местоположение" Width="360" Margin="90 20 0 0"></TextBox>
+					<TextBox Text="{Binding EditOutletVM.CurrentOutlet.Location}" Watermark="Местоположение" Width="360" Margin="90 20 0 0"></TextBox>
 				</StackPanel>
 				<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 				<StackPanel Orientation="Vertical">
 					<TextBlock Classes="TextToTextBox">Проекты:</TextBlock>
-					<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
-						<TextBlock>Проект “...”</TextBlock>
-					</CheckBox>
-					<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
-						<TextBlock>Проект “...”</TextBlock>
-					</CheckBox>
-					<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
-						<TextBlock>Проект “...”</TextBlock>
-					</CheckBox>
+					<ListBox ItemsSource="{Binding ListProjects}">
+						<ListBox.ItemTemplate>
+							<DataTemplate>
+								<StackPanel Orientation="Vertical">
+									<CheckBox Classes="TextToCheckBox" Margin="202 10 0 0">
+										<TextBlock Text="{Binding Title}"></TextBlock>
+									</CheckBox>
+								</StackPanel>
+							</DataTemplate>
+						</ListBox.ItemTemplate>
+					</ListBox>
 				</StackPanel>
 			</StackPanel>
 			</ScrollViewer>
@@ -236,7 +234,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="">
+			<Button Classes="BtSave" Command="{Binding SaveEditOutlet}">
 				<TextBlock Classes="TextBtSave">Сохранить</TextBlock>
 			</Button>
 		</StackPanel>

+ 2 - 1
Views/EmployeesView.axaml

@@ -265,7 +265,7 @@
 									<TextBlock Text="{Binding Patronymic}" Classes="Data" >Типа отчество</TextBlock>
 								</Border>
 								<Border  Classes="Data" CornerRadius="13"  Width="130" Height="40" Margin="0 0 63 0">
-									<TextBlock Text="{Binding Role}" Classes="Data">Типа  роль</TextBlock>
+									<TextBlock Text="{Binding RoleNavigation.Title}" Classes="Data">Типа  роль</TextBlock>
 								</Border>
 								<Border  Classes="Data" CornerRadius="13"  Width="150" Height="40" Margin="0 0 55 0">
 									<TextBlock Text="{Binding Email}" Classes="Data">Типа  почта</TextBlock>
@@ -273,6 +273,7 @@
 								<Border  Classes="Data" CornerRadius="13"  Width="170" Height="40">
 									<TextBlock Text="{Binding Phonenumber}" Classes="Data">Типа  телефон</TextBlock>
 								</Border>
+									<Button Content="Изменить" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).EditUser}" CommandParameter ="{Binding Employeesid}"/>
 							</StackPanel>
 						</DataTemplate>
 					</ListBox.ItemTemplate>

+ 1 - 0
Views/OutletsView.axaml

@@ -215,6 +215,7 @@
 									<Border  Classes="Data" CornerRadius="13"  Width="280" Height="40">
 										<TextBlock Text="{Binding Location}" Classes="Data">Типа  местоположение</TextBlock>
 									</Border>
+									<Button Content="Изменить" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).EditOutlet}" CommandParameter ="{Binding Outletid}"/>
 								</StackPanel>
 							</DataTemplate>
 						</ListBox.ItemTemplate>