ЧернощековаАР 1 hónapja
szülő
commit
243e367f31

+ 6 - 1
AvaloniaApplication2/ViewModels/MainWindowViewModel.cs

@@ -11,7 +11,7 @@ namespace AvaloniaApplication2.ViewModels
 {
     public partial class MainWindowViewModel : ViewModelBase
     {
-        ChernoshchekovaContext db = new ChernoshchekovaContext();
+        
 
         [ObservableProperty] string buttonText;
         [ObservableProperty] string login;
@@ -22,6 +22,11 @@ namespace AvaloniaApplication2.ViewModels
         [ObservableProperty] List<Gender> gendersList;
 
         [ObservableProperty] UserControl page = new AvaloniaApplication2.Views.Authorization();
+
+        public MainWindowViewModel()
+        {
+            GendersList = db.Genders.ToList();
+        }
        
         public DateTimeOffset DateTimeOffset
         {

+ 11 - 9
AvaloniaApplication2/ViewModels/PageForAdminViewModel.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using AvaloniaApplication2.Views;
 using Avalonia.Controls;
 using Avalonia.Media.TextFormatting;
 using CommunityToolkit.Mvvm.ComponentModel;
@@ -13,8 +14,6 @@ namespace AvaloniaApplication2.ViewModels
 {
     public partial class PageForAdminViewModel:ViewModelBase
     {
-        ChernoshchekovaContext db = new ChernoshchekovaContext();
-
         [ObservableProperty] List<User> users;
         [ObservableProperty] List<User> users0;
         [ObservableProperty] string textFind;
@@ -23,9 +22,9 @@ namespace AvaloniaApplication2.ViewModels
 
         [ObservableProperty] List<Gender> gendersList;
 
-        public PageForAdminViewModel(List<User> users)
+        public PageForAdminViewModel()
         {
-            users = db.Users.Include(x => x.Logined.IdRole).ToList();
+            users = db.Users.Include(x=>x.GenderNavigation).ToList();
             genders =
                 [
                 new Gender() {NameGender = "Сбросить фильтр", IdGender = 0},
@@ -33,16 +32,17 @@ namespace AvaloniaApplication2.ViewModels
                 ];
             users0 = users;
         }
+        partial void OnTextFindChanged(string value) => AllFilters();
 
         public void DateSort(int idCB)
         {
             switch (idCB)
             {
                 case 1:
-                    users = users.OrderBy(x => x.BirthDate).ToList();
+                    Users = Users.OrderBy(x => x.BirthDate).ToList();
                     break;
                 case 2:
-                    users = users.OrderByDescending(x => x.BirthDate).ToList();
+                    Users = Users.OrderByDescending(x => x.BirthDate).ToList();
                     break;
             }
         }
@@ -51,9 +51,11 @@ namespace AvaloniaApplication2.ViewModels
 
         void AllFilters()
         {
-            users = users0;
-            if (!string.IsNullOrEmpty(textFind)) users = users.Where(x => x.UserName.Contains(textFind)).ToList();
-            if (filteredGender != null && filteredGender.IdGender != 0) users = users.Where(x => x.GenderNavigation == filteredGender).ToList();
+            Users = Users0;
+            if (!string.IsNullOrEmpty(textFind)) Users = Users.Where(x => x.UserName.Contains(textFind)).ToList();
+            if (filteredGender != null && filteredGender.IdGender != 0) Users = Users.Where(x => x.GenderNavigation == filteredGender).ToList();
         }
+
+
     }
 }

+ 39 - 0
AvaloniaApplication2/ViewModels/UserProfileViewModel.cs

@@ -0,0 +1,39 @@
+using Avalonia.Controls;
+using AvaloniaApplication2.Views;
+using AvaloniaApplication2.ViewModels;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace AvaloniaApplication2.ViewModels
+{
+    public partial class UserProfileViewModel : ViewModelBase
+    {
+        [ObservableProperty] User editedUser;
+        [ObservableProperty] List<Gender> gendersList;
+
+        [ObservableProperty] UserControl page = new AvaloniaApplication2.Views.UserProfile();
+
+        public UserProfileViewModel(int id)
+        {
+            GendersList = db.Genders.ToList();
+            editedUser = db.Users.Include(x => x.GenderNavigation).FirstOrDefault(x => x.IdUser == id);
+        }
+
+        public DateTimeOffset DateTimeOffset
+        {
+            get => new DateTimeOffset((DateTime)editedUser.BirthDate, TimeSpan.Zero);
+            set => editedUser.BirthDate = new DateTime(value.Year, value.Month, value.Day);
+        }
+
+        public void GoBack()
+        {
+            page = new AvaloniaApplication2.Views.Authorization();
+        }
+
+        public void Save() => db.SaveChanges();
+    }
+}

+ 1 - 0
AvaloniaApplication2/ViewModels/ViewModelBase.cs

@@ -4,5 +4,6 @@ namespace AvaloniaApplication2.ViewModels
 {
     public class ViewModelBase : ObservableObject
     {
+       static protected ChernoshchekovaContext db = new ChernoshchekovaContext();
     }
 }

+ 7 - 7
AvaloniaApplication2/Views/PageForAdmin.axaml

@@ -8,9 +8,9 @@
 			 x:DataType="vm:PageForAdminViewModel"
 			 Background="LightGray">
 	<Grid RowDefinitions="70,*">
-		<StackPanel Orientation="Horizontal" Grid.Row="0">
+		<StackPanel Orientation="Vertical" Grid.Row="0">
 			<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
-				<TextBox Text="{Binding TextFind}" Watermark="Введите текст для поиска" Height="" Width="350" />
+				<TextBox Text="{Binding TextFind}" Watermark="Введите текст для поиска" Height="40" Width="350" />
 				<StackPanel Orientation="Vertical">
 					<TextBlock Text="Сортировка по дате рождения" Padding="10,5,5,0" Margin="5"/>
 					<RadioButton Content="По возрастанию" Command="{Binding DateSort}" CommandParameter="1" Margin="15,0,0,0"/>
@@ -27,14 +27,14 @@
 					</ComboBox>
 				</StackPanel>
 			</StackPanel>
-			<ListBox ItemsSource="{Binding Users}" Grid.Row="1">
+			<ListBox ItemsSource="{Binding Users}" Grid.Row="1" Padding="5">
 				<ListBox.ItemTemplate>
 					<DataTemplate>
 						<StackPanel>
-							<TextBlock Text="{Binding UserName}"/>
-							<TextBlock Text="{Binding BirthDate}"/>
-							<TextBlock Text="{Binding GenderNavigation.NameGender}"/>
-							<TextBlock Text="{Binding Logined.IdRoleNavigation.IdRole}"/>
+							<TextBlock Text="{Binding UserName, StringFormat=Имя: {0}}"/>
+							<TextBlock Text="{Binding BirthDate, StringFormat=Дата рождения: {0:dd/MM/yyyy}}"/>
+							<TextBlock Text="{Binding GenderNavigation.NameGender, StringFormat=Пол: {0}}"/>
+							<TextBlock Text="{Binding Logined.IdRoleNavigation.IdRole, StringFormat=Роль в системе: {0}}"/>
 							<Button Content="Изменить персональные данные пользователя" Command="" CommandParameter="{Binding IdUser}"/>
 						</StackPanel>
 					</DataTemplate>

+ 2 - 0
AvaloniaApplication2/Views/PageForAdmin.axaml.cs

@@ -1,6 +1,7 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
+using AvaloniaApplication2.ViewModels;
 
 namespace AvaloniaApplication2;
 
@@ -9,5 +10,6 @@ public partial class PageForAdmin : UserControl
     public PageForAdmin()
     {
         InitializeComponent();
+        DataContext = new PageForAdminViewModel();
     }
 }