ШмелевМВ 1 هفته پیش
والد
کامیت
7b045b98a8

+ 13 - 0
AvaloniaApplicationTestNew/Models/Trait.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+
+namespace AvaloniaApplicationTestNew.Models;
+
+public partial class Trait
+{
+    public int Idtrait { get; set; }
+
+    public string Traitname { get; set; } = null!;
+
+    public virtual ICollection<User> IdUsers { get; set; } = new List<User>();
+}

+ 2 - 0
AvaloniaApplicationTestNew/Models/User.cs

@@ -18,4 +18,6 @@ public partial class User
     public virtual Gender IdGenderNavigation { get; set; } = null!;
 
     public virtual Logined IdUserNavigation { get; set; } = null!;
+
+    public virtual ICollection<Trait> IdTraits { get; set; } = new List<Trait>();
 }

+ 33 - 0
AvaloniaApplicationTestNew/Models/_41pShmelevMvContext.cs

@@ -21,6 +21,8 @@ public partial class _41pShmelevMvContext : DbContext
 
     public virtual DbSet<Role> Roles { get; set; }
 
+    public virtual DbSet<Trait> Traits { get; set; }
+
     public virtual DbSet<User> Users { get; set; }
 
     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
@@ -76,6 +78,18 @@ public partial class _41pShmelevMvContext : DbContext
                 .HasColumnName("role_name");
         });
 
+        modelBuilder.Entity<Trait>(entity =>
+        {
+            entity.HasKey(e => e.Idtrait).HasName("trait_pk");
+
+            entity.ToTable("trait");
+
+            entity.Property(e => e.Idtrait).HasColumnName("idtrait");
+            entity.Property(e => e.Traitname)
+                .HasColumnType("character varying")
+                .HasColumnName("traitname");
+        });
+
         modelBuilder.Entity<User>(entity =>
         {
             entity.HasKey(e => e.IdUser).HasName("users_pk");
@@ -104,6 +118,25 @@ public partial class _41pShmelevMvContext : DbContext
             entity.HasOne(d => d.IdUserNavigation).WithOne(p => p.User)
                 .HasForeignKey<User>(d => d.IdUser)
                 .HasConstraintName("users_logined_fk");
+
+            entity.HasMany(d => d.IdTraits).WithMany(p => p.IdUsers)
+                .UsingEntity<Dictionary<string, object>>(
+                    "UserTrait",
+                    r => r.HasOne<Trait>().WithMany()
+                        .HasForeignKey("IdTrait")
+                        .OnDelete(DeleteBehavior.ClientSetNull)
+                        .HasConstraintName("user_traits_trait_fk"),
+                    l => l.HasOne<User>().WithMany()
+                        .HasForeignKey("IdUser")
+                        .OnDelete(DeleteBehavior.Restrict)
+                        .HasConstraintName("user_traits_users_fk"),
+                    j =>
+                    {
+                        j.HasKey("IdUser", "IdTrait").HasName("user_traits_pk");
+                        j.ToTable("user_traits");
+                        j.IndexerProperty<int>("IdUser").HasColumnName("id_user");
+                        j.IndexerProperty<int>("IdTrait").HasColumnName("id_trait");
+                    });
         });
 
         OnModelCreatingPartial(modelBuilder);

+ 2 - 1
AvaloniaApplicationTestNew/ViewModels/AdminPageViewModel.cs

@@ -42,7 +42,7 @@ namespace AvaloniaApplicationTestNew.ViewModels
 
         public AdminPageViewModel() 
         { 
-            Users = myContext.Users.Include(x => x.IdUserNavigation.IdRoleNavigation).Include(x => x.IdGenderNavigation).ToList();
+            Users = myContext.Users.Include(x => x.IdUserNavigation.IdRoleNavigation).Include(x => x.IdGenderNavigation).Include(x => x.IdTraits).ToList();
             int count = 0;
             LocalListusers = RemakeList(users);
             localUser = LocalListusers;
@@ -67,6 +67,7 @@ namespace AvaloniaApplicationTestNew.ViewModels
                         IdUser = user.IdUser,
                         IdUserNavigation = user.IdUserNavigation,
                         BirthDate = user.BirthDate,
+                        IdTraits = user.IdTraits,
                         ConvertImage = user.Image != null ? new Bitmap(new MemoryStream(user.Image)) : new Bitmap("Assets\\ava.png")
                     };
                 LocalListusers.Add(temp);

+ 0 - 1
AvaloniaApplicationTestNew/ViewModels/UserPageViewModel.cs

@@ -31,7 +31,6 @@ namespace AvaloniaApplicationTestNew.ViewModels
             Current_user = myContext.Users.Include(x => x.IdGenderNavigation).FirstOrDefault(x => x.IdUser == id);
             GendersList = myContext.Genders.ToList();
             imageUser = Current_user.Image != null ? new Bitmap(new MemoryStream(Current_user.Image)) : new Bitmap("Assets\\ava.png");
-            
         }
         public void SaveAndChange()
         {

+ 19 - 16
AvaloniaApplicationTestNew/Views/AdminPage.axaml

@@ -6,8 +6,8 @@
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="AvaloniaApplicationTestNew.AdminPage"
 			 x:DataType="vm:AdminPageViewModel">
-	
-	<Grid RowDefinitions="75,50,*" ColumnDefinitions="*">
+
+	<Grid RowDefinitions="75,50,*" ColumnDefinitions="*,*,*">
 		<StackPanel Orientation="Horizontal" Grid.Row="0" Margin="0 10 0 10">
 			<TextBlock Text="Поиск:"/>
 			<TextBox Text="{Binding FindText}" Watermark="Введите текст для поиска"/>
@@ -25,26 +25,29 @@
 				</ComboBox.ItemTemplate>
 			</ComboBox>
 		</StackPanel>
-		<StackPanel Grid.Row="1" HorizontalAlignment="Center" Orientation="Horizontal">
+		<StackPanel Grid.Row="1" Grid.ColumnSpan="3" HorizontalAlignment="Center" Orientation="Horizontal">
 			<Button Content="Добавить пользователя" Command="{Binding AddUser}"/>
 			<Button Content="Выйти" Command="{Binding Exit}"/>
 		</StackPanel>
-		<ListBox ItemsSource="{Binding LocalListusers}" Grid.Row="2" Background="Linen" Grid.Column="0">
+		<ListBox ItemsSource="{Binding LocalListusers}" Grid.Row="2" Background="Linen" Grid.ColumnSpan="3">
 			<ListBox.ItemTemplate>
 				<DataTemplate>
 					<StackPanel>
-						<Grid ColumnDefinitions="*, 200">
-							<StackPanel Grid.Column="0">
-								<TextBlock Text="{Binding Name, StringFormat=Имя: {0}}"/>
-								<TextBlock Text="{Binding BirthDate, StringFormat=Дата рождения: {0:dd/MM/yyyy}}"/>
-								<TextBlock Text="{Binding IdGenderNavigation.Gender1, StringFormat=Пол: {0}}"/>
-								<TextBlock Text="{Binding IdUserNavigation.IdRoleNavigation.RoleName, StringFormat=Роль в системе: {0}}"/>
-								<Button Content="Изменить персональные данные пользователя" Command="{Binding $parent[UserControl].((vm:AdminPageViewModel)DataContext).InfoUsers}" CommandParameter="{Binding IdUser}"/>
-								<Grid ColumnDefinitions="*, *" Grid.Column="1">
-									<Image Grid.Column="1" Source="{Binding ConvertImage}" Width="150" Height="150"/>
-								</Grid>
-							</StackPanel>
-						</Grid>
+						<StackPanel Grid.Column="1">
+							<TextBlock Text="{Binding Name, StringFormat=Имя: {0}}"/>
+							<TextBlock Text="{Binding BirthDate, StringFormat=Дата рождения: {0:dd/MM/yyyy}}"/>
+							<TextBlock Text="{Binding IdGenderNavigation.Gender1, StringFormat=Пол: {0}}"/>
+							<TextBlock Text="{Binding IdUserNavigation.IdRoleNavigation.RoleName, StringFormat=Роль в системе: {0}}"/>
+							<Button Content="Изменить персональные данные пользователя" Command="{Binding $parent[UserControl].((vm:AdminPageViewModel)DataContext).InfoUsers}" CommandParameter="{Binding IdUser}"/>
+						</StackPanel>
+						<ListBox ItemsSource="{Binding IdTraits}" Grid.Column="2" Grid.Row="2">
+							<ListBox.ItemTemplate>
+								<DataTemplate>
+									<TextBlock Text="{Binding Traitname}"/>
+								</DataTemplate>
+							</ListBox.ItemTemplate>
+						</ListBox>
+						<Image Source="{Binding ConvertImage}" Width="150" Height="150" Grid.Row="2" Grid.Column="3"/>
 					</StackPanel>
 				</DataTemplate>
 			</ListBox.ItemTemplate>