Katya před 5 měsíci
rodič
revize
9260015034

+ 13 - 0
Models/Availability.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+
+namespace YtYtAvalonia.Models;
+
+public partial class Availability
+{
+    public int Availabilityid { get; set; }
+
+    public string Title { get; set; } = null!;
+
+    public virtual ICollection<Course> Courses { get; set; } = new List<Course>();
+}

+ 17 - 0
Models/Course.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+
+namespace YtYtAvalonia.Models;
+
+public partial class Course
+{
+    public int Courseid { get; set; }
+
+    public string Title { get; set; } = null!;
+
+    public int Availability { get; set; }
+
+    public int? Price { get; set; }
+
+    public virtual Availability AvailabilityNavigation { get; set; } = null!;
+}

+ 118 - 0
Models/SuharevaContext.cs

@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore;
+
+namespace YtYtAvalonia.Models;
+
+public partial class SuharevaContext : DbContext
+{
+    public SuharevaContext()
+    {
+    }
+
+    public SuharevaContext(DbContextOptions<SuharevaContext> options)
+        : base(options)
+    {
+    }
+
+    public virtual DbSet<Availability> Availabilities { get; set; }
+
+    public virtual DbSet<Course> Courses { get; set; }
+
+    public virtual DbSet<User> Users { get; set; }
+
+    public virtual DbSet<UserAndCourse> UserAndCourses { 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 http://go.microsoft.com/fwlink/?LinkId=723263.
+        => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.ru;Port=5442;Database=Suhareva;Username=33P;Password=12345");
+
+    protected override void OnModelCreating(ModelBuilder modelBuilder)
+    {
+        modelBuilder.Entity<Availability>(entity =>
+        {
+            entity.HasKey(e => e.Availabilityid).HasName("Availability_pkey");
+
+            entity.ToTable("Availability");
+
+            entity.Property(e => e.Availabilityid)
+                .UseIdentityAlwaysColumn()
+                .HasColumnName("availabilityid");
+            entity.Property(e => e.Title)
+                .HasMaxLength(50)
+                .HasColumnName("title");
+        });
+
+        modelBuilder.Entity<Course>(entity =>
+        {
+            entity.HasKey(e => e.Courseid).HasName("Course_pkey");
+
+            entity.ToTable("Course");
+
+            entity.Property(e => e.Courseid)
+                .UseIdentityAlwaysColumn()
+                .HasColumnName("courseid");
+            entity.Property(e => e.Availability).HasColumnName("availability");
+            entity.Property(e => e.Price).HasColumnName("price");
+            entity.Property(e => e.Title)
+                .HasMaxLength(50)
+                .HasColumnName("title");
+
+            entity.HasOne(d => d.AvailabilityNavigation).WithMany(p => p.Courses)
+                .HasForeignKey(d => d.Availability)
+                .OnDelete(DeleteBehavior.ClientSetNull)
+                .HasConstraintName("Course_availability_fkey");
+        });
+
+        modelBuilder.Entity<User>(entity =>
+        {
+            entity.HasKey(e => e.Userid).HasName("User_pkey");
+
+            entity.ToTable("User");
+
+            entity.Property(e => e.Userid)
+                .UseIdentityAlwaysColumn()
+                .HasColumnName("userid");
+            entity.Property(e => e.Bithday).HasColumnName("bithday");
+            entity.Property(e => e.Email)
+                .HasMaxLength(50)
+                .HasColumnName("email");
+            entity.Property(e => e.Login)
+                .HasMaxLength(50)
+                .HasColumnName("login");
+            entity.Property(e => e.Name).HasMaxLength(50);
+            entity.Property(e => e.Password).HasMaxLength(50);
+            entity.Property(e => e.Patronymic)
+                .HasMaxLength(50)
+                .HasColumnName("patronymic");
+            entity.Property(e => e.Phonenumber).HasColumnName("phonenumber");
+            entity.Property(e => e.Surname)
+                .HasMaxLength(50)
+                .HasColumnName("surname");
+        });
+
+        modelBuilder.Entity<UserAndCourse>(entity =>
+        {
+            entity
+                .HasNoKey()
+                .ToTable("UserAndCourse");
+
+            entity.Property(e => e.Courseid).HasColumnName("courseid");
+            entity.Property(e => e.Userid).HasColumnName("userid");
+
+            entity.HasOne(d => d.Course).WithMany()
+                .HasForeignKey(d => d.Courseid)
+                .OnDelete(DeleteBehavior.ClientSetNull)
+                .HasConstraintName("UserAndCourse_courseid_fkey");
+
+            entity.HasOne(d => d.User).WithMany()
+                .HasForeignKey(d => d.Userid)
+                .OnDelete(DeleteBehavior.ClientSetNull)
+                .HasConstraintName("UserAndCourse_userid_fkey");
+        });
+
+        OnModelCreatingPartial(modelBuilder);
+    }
+
+    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
+}

+ 27 - 0
Models/User.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+
+namespace YtYtAvalonia.Models;
+
+public partial class User
+{
+    public int Userid { get; set; }
+
+    public string Login { get; set; } = null!;
+
+    public string? Surname { get; set; }
+
+    public string? Name { get; set; }
+
+    public string? Patronymic { get; set; }
+
+    public string Password { get; set; } = null!;
+
+    public DateOnly Bithday { get; set; }
+
+    public string Email { get; set; } = null!;
+
+    public int Phonenumber { get; set; }
+
+    public int? Result { get; set; }
+}

+ 15 - 0
Models/UserAndCourse.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+
+namespace YtYtAvalonia.Models;
+
+public partial class UserAndCourse
+{
+    public int Userid { get; set; }
+
+    public int Courseid { get; set; }
+
+    public virtual Course Course { get; set; } = null!;
+
+    public virtual User User { get; set; } = null!;
+}

+ 12 - 1
ViewModels/MainWindowViewModel.cs

@@ -1,4 +1,8 @@
-using Avalonia.Controls;
+using YtYtAvalonia.Models;
+using YtYtAvalonia.Views;
+using YtYtAvalonia.ViewModels;
+
+using Avalonia.Controls;
 using ReactiveUI;
 using YtYtAvalonia.View;
 
@@ -7,6 +11,13 @@ namespace YtYtAvalonia.ViewModels
     public class MainWindowViewModel : ViewModelBase
     {
 #pragma warning disable CA1822 // Mark members as static
+
+        public static SuharevaContext myConnection = new SuharevaContext();
+
+        RegistrationViewModel regPage = new RegistrationViewModel(myConnection);
+        public RegistrationViewModel RegPage { get => regPage; set => regPage = value; }
+
+#pragma warning restore CA1822 // Mark members as static
         public string Greeting => "Welcome to Avalonia!";
 
 //        public UserControl Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }

+ 44 - 0
ViewModels/RegistrationViewModel.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+using YtYtAvalonia.Models;
+
+namespace YtYtAvalonia.ViewModels
+{
+	public class RegistrationViewModel : ReactiveObject
+	{
+        /*string login = "";
+		string password = "";
+        string surname = "";
+        string name = "";
+        string patronymic = "";
+        int day;
+        int month;
+        int year;
+        string email = "";
+        int phone;
+
+        public string Login { get => login; set => login = value; }
+        public string Password { get => password; set => password = value; }
+        public string Surname { get => surname; set => surname = value; }
+        public string Name { get => name; set => name = value; }
+        public string Patronymic { get => patronymic; set => patronymic = value; }
+        public int Day { get => day; set => day = value; }
+        public int Month { get => month; set => month = value; }
+        public int Year { get => year; set => year = value; }
+        public string Email { get => email; set => email = value; }
+        public int Phone { get => phone; set => phone = value; }*/
+
+        SuharevaContext myConnection;
+        User currentUser;
+        public RegistrationViewModel(SuharevaContext myConnection)
+        {
+            this.myConnection = myConnection;
+            CurrentUser = new User();
+            myConnection.Add(CurrentUser);
+            myConnection.SaveChanges();
+        }
+
+        public User CurrentUser { get => currentUser; set => currentUser = value; }
+    }
+}

+ 4 - 1
Views/RegistrationView.axaml

@@ -3,6 +3,9 @@
 			 xmlns:vm="using:YtYtAvalonia.ViewModels"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+			 xmlns:vm="using:YtYtAvalonia.ViewModels"
+			 x:DataType="vm:MainWindowViewModel"
              mc:Ignorable="d" d:DesignWidth="1920" d:DesignHeight="1080"
              x:Class="YtYtAvalonia.View.RegistrationView">
 	<Grid>
@@ -36,7 +39,7 @@
 			</StackPanel.Styles>
 
 			<TextBlock HorizontalAlignment="Center" Margin="0 0 0 30" FontFamily="Roboto" FontSize="25" FontWeight="Bold">Регистрация</TextBlock>
-			<TextBox Watermark="Логин" Width="360" FontSize="13" Margin="0 0 0 10" ></TextBox>
+			<TextBox Text="{}" Watermark="Логин" Width="360" FontSize="13" Margin="0 0 0 10" ></TextBox>
 			<TextBox Watermark="Пароль" PasswordChar="•" Width="360" ></TextBox>
 			<TextBlock Margin="0 25 0 0"  FontFamily="Roboto" FontSize="14">Личные данные:</TextBlock>
 			<TextBox Watermark="Фамилия" Width="360" FontSize="13" Margin="0 10 0 10" ></TextBox>

+ 3 - 1
Views/RegistrationView.axaml.cs

@@ -1,6 +1,8 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
+using YtYtAvalonia.ViewModels;
+using YtYtAvalonia.Models;
 
 namespace YtYtAvalonia.View;
 
@@ -8,6 +10,6 @@ public partial class RegistrationView : UserControl
 {
     public RegistrationView()
     {
-        InitializeComponent();
+
     }
 }

+ 5 - 0
YtYtAvalonia.csproj

@@ -21,5 +21,10 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
   </ItemGroup>
 </Project>