浏览代码

создание галереи для пользователя

ЧернощековаАР 1 周之前
父节点
当前提交
7b67b087cf

+ 20 - 1
AvaloniaApplication2/ChernoshchekovaContext.cs

@@ -25,6 +25,8 @@ public partial class ChernoshchekovaContext : DbContext
 
     public virtual DbSet<User> Users { get; set; }
 
+    public virtual DbSet<Userimage> Userimages { get; set; }
+
     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
         => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.local;Port=5432;Database=chernoshchekova;Username=31P;Password=12345");
@@ -123,7 +125,6 @@ public partial class ChernoshchekovaContext : DbContext
                     "Usertrait",
                     r => r.HasOne<Trait>().WithMany()
                         .HasForeignKey("Idtrait")
-                        .OnDelete(DeleteBehavior.ClientSetNull)
                         .HasConstraintName("usertraits_trait_fk"),
                     l => l.HasOne<User>().WithMany()
                         .HasForeignKey("Iduser")
@@ -141,6 +142,24 @@ public partial class ChernoshchekovaContext : DbContext
                     });
         });
 
+        modelBuilder.Entity<Userimage>(entity =>
+        {
+            entity.HasKey(e => e.Id).HasName("userimage_pk");
+
+            entity.ToTable("userimage");
+
+            entity.Property(e => e.Id).HasColumnName("id");
+            entity.Property(e => e.IdUser)
+                .ValueGeneratedOnAdd()
+                .HasColumnName("id_user");
+            entity.Property(e => e.Image).HasColumnName("image");
+
+            entity.HasOne(d => d.IdUserNavigation).WithMany(p => p.Userimages)
+                .HasForeignKey(d => d.IdUser)
+                .OnDelete(DeleteBehavior.ClientSetNull)
+                .HasConstraintName("userimage_users_fk");
+        });
+
         OnModelCreatingPartial(modelBuilder);
     }
 

+ 2 - 0
AvaloniaApplication2/User.cs

@@ -19,5 +19,7 @@ public partial class User
 
     public virtual Logined IdUserNavigation { get; set; } = null!;
 
+    public virtual ICollection<Userimage> Userimages { get; set; } = new List<Userimage>();
+
     public virtual ICollection<Trait> Idtraits { get; set; } = new List<Trait>();
 }

+ 15 - 0
AvaloniaApplication2/UserImage.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+
+namespace AvaloniaApplication2;
+
+public partial class Userimage
+{
+    public long Id { get; set; }
+
+    public long IdUser { get; set; }
+
+    public byte[] Image { get; set; } = null!;
+
+    public virtual User IdUserNavigation { get; set; } = null!;
+}

+ 2 - 0
AvaloniaApplication2/ViewModels/UserProfileViewModel.cs

@@ -21,6 +21,7 @@ namespace AvaloniaApplication2.ViewModels
         [ObservableProperty] Logined editedLogin;
         [ObservableProperty] List<Gender> gendersList;
         [ObservableProperty] Bitmap imageUser;
+        [ObservableProperty] List<Userimage> imagesUsers;
 
         public UserProfileViewModel()
         {
@@ -33,6 +34,7 @@ namespace AvaloniaApplication2.ViewModels
             GendersList = db.Genders.ToList();
             editedLogin = db.Logineds.Include(x => x.User.GenderNavigation).Include(x=>x.User.Idtraits).FirstOrDefault(x => x.User.IdUser == id);
             imageUser = EditedLogin.User.Image != null ? new Bitmap(new MemoryStream(editedLogin.User.Image)) : new Bitmap("C:/Users/ЧернощековаАР/source/repos/AvaloniaApplication2/AvaloniaApplication2/Assets/профиль.png");
+            imagesUsers = db.Userimages.Where(x => x.IdUser == id).ToList();
         }
 
         public DateTimeOffset DateTimeOffset

+ 2 - 1
AvaloniaApplication2/Views/UserProfile.axaml

@@ -40,7 +40,8 @@
 			</StackPanel>
 		</StackPanel>
 		<Button Command="{Binding UserProfileVM.Save}" Content="СОХРАНИТЬ ИЗМЕНЕНИЯ" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
-		<Button Content="Выбрать изображение пользователя" Command="{Binding UserProfileVM.Image}" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<Button Content="Добавить изображение пользователя" Command="{Binding UserProfileVM.Image}" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
+		<Button Content="Посмотреть все фото пользователя" Command="" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<Button Command="{Binding UserProfileVM.GoBack}" Content="ВЫХОД" VerticalAlignment="Top" HorizontalAlignment="Center" Padding="" Margin="5" Background="White" Foreground="Black" Width="" Height="30"/>
 		<TextBlock Text="Развлекаловка" HorizontalAlignment="Center" VerticalAlignment="Bottom" Classes="AnimatedTB" Padding="0,40,0,0"/>
 	</StackPanel>