Browse Source

Add registration (happy happy happy)

AngelikaSuhareva 5 months ago
parent
commit
c25b595f20

+ 1 - 0
Models/SuharevaContext.cs

@@ -8,6 +8,7 @@ public partial class SuharevaContext : DbContext
 {
 {
     public SuharevaContext()
     public SuharevaContext()
     {
     {
+        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
     }
     }
 
 
     public SuharevaContext(DbContextOptions<SuharevaContext> options)
     public SuharevaContext(DbContextOptions<SuharevaContext> options)

+ 1 - 1
Models/User.cs

@@ -17,7 +17,7 @@ public partial class User
 
 
     public string Password { get; set; } = null!;
     public string Password { get; set; } = null!;
 
 
-    public DateOnly Bithday { get; set; }
+    public DateTime Bithday { get; set; }
 
 
     public string Email { get; set; } = null!;
     public string Email { get; set; } = null!;
 
 

+ 18 - 3
ViewModels/MainWindowViewModel.cs

@@ -14,19 +14,28 @@ namespace YtYtAvalonia.ViewModels
 
 
         public static SuharevaContext myConnection = new SuharevaContext();
         public static SuharevaContext myConnection = new SuharevaContext();
 
 
-        RegistrationViewModel regPage = new RegistrationViewModel(myConnection);
-        public RegistrationViewModel RegPage { get => regPage; set => regPage = value; }
+        RegistrationViewModel regVM = new RegistrationViewModel(myConnection);
+        public RegistrationViewModel RegVM { get => regVM; set => regVM = value; }
 
 
         public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
         public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
         
         
         private UserControl uc = new LoginView();
         private UserControl uc = new LoginView();
 
 
-        public void LoadRegistrationView() => UC = new RegistrationView();
+        public void LoadRegistrationView() 
+        {
+            UC = new RegistrationView();
+            
+        }
 
 
         public void LoadLoginView() => UC = new LoginView();
         public void LoadLoginView() => UC = new LoginView();
 
 
         LoginViewModel loginVM = new LoginViewModel();
         LoginViewModel loginVM = new LoginViewModel();
 
 
+        public void CreateUser()
+        {
+            RegVM = new RegistrationViewModel(myConnection);
+            UC = new LoginView();
+        }
         
         
         public LoginViewModel LoginVM { get => loginVM; set => loginVM = value; }
         public LoginViewModel LoginVM { get => loginVM; set => loginVM = value; }
 
 
@@ -43,5 +52,11 @@ namespace YtYtAvalonia.ViewModels
                 UC = new PersonalAccount();
                 UC = new PersonalAccount();
             }
             }
         }
         }
+
+        public void SaveData()
+        {
+            myConnection.SaveChanges();
+            UC = new PersonalAccount();
+        }
     }
     }
 }
 }

+ 8 - 25
ViewModels/RegistrationViewModel.cs

@@ -2,43 +2,26 @@ using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using ReactiveUI;
 using ReactiveUI;
 using YtYtAvalonia.Models;
 using YtYtAvalonia.Models;
+using YtYtAvalonia.ViewModels;
 
 
 namespace YtYtAvalonia.ViewModels
 namespace YtYtAvalonia.ViewModels
 {
 {
 	public class RegistrationViewModel : ReactiveObject
 	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;
         SuharevaContext myConnection;
         User currentUser;
         User currentUser;
         public RegistrationViewModel(SuharevaContext myConnection)
         public RegistrationViewModel(SuharevaContext myConnection)
         {
         {
-            //this.myConnection = myConnection;
-            //CurrentUser = new User();
-            //myConnection.Add(CurrentUser);
-            //myConnection.SaveChanges();
+            this.myConnection = myConnection;
+            CurrentUser = new User();
+            myConnection.Add(currentUser);
         }
         }
+        
 
 
+        public string Birthday { get => currentUser.Bithday.ToString(); set => currentUser.Bithday = Convert.ToDateTime(value); }
         public User CurrentUser { get => currentUser; set => currentUser = value; }
         public User CurrentUser { get => currentUser; set => currentUser = value; }
+
+
     }
     }
 }
 }

+ 9 - 9
Views/RegistrationView.axaml

@@ -37,19 +37,19 @@
 			</StackPanel.Styles>
 			</StackPanel.Styles>
 
 
 			<TextBlock HorizontalAlignment="Center" Margin="0 0 0 30" FontFamily="Roboto" FontSize="25" FontWeight="Bold">Регистрация</TextBlock>
 			<TextBlock HorizontalAlignment="Center" Margin="0 0 0 30" FontFamily="Roboto" FontSize="25" FontWeight="Bold">Регистрация</TextBlock>
-			<TextBox Text="{}" Watermark="Логин" Width="360" FontSize="13" Margin="0 0 0 10" ></TextBox>
-			<TextBox Watermark="Пароль" PasswordChar="•" Width="360" ></TextBox>
+			<TextBox Text="{Binding RegVM.CurrentUser.Login}" Watermark="Логин" Width="360" FontSize="13" Margin="0 0 0 10" ></TextBox>
+			<TextBox Text="{Binding RegVM.CurrentUser.Password}" Watermark="Пароль" PasswordChar="•" Width="360" ></TextBox>
 			<TextBlock Margin="0 25 0 0"  FontFamily="Roboto" FontSize="14">Личные данные:</TextBlock>
 			<TextBlock Margin="0 25 0 0"  FontFamily="Roboto" FontSize="14">Личные данные:</TextBlock>
-			<TextBox Watermark="Фамилия" Width="360" FontSize="13" Margin="0 10 0 10" ></TextBox>
-			<TextBox Watermark="Имя" Width="360" FontSize="13" Margin="0 0 0 10" ></TextBox>
-			<TextBox Watermark="Отчество" Width="360" FontSize="13" Margin="0 0 0 25" ></TextBox>
+			<TextBox Text="{Binding RegVM.CurrentUser.Surname}" Watermark="Фамилия" Width="360" FontSize="13" Margin="0 10 0 10" ></TextBox>
+			<TextBox Text="{Binding RegVM.CurrentUser.Name}" Watermark="Имя" Width="360" FontSize="13" Margin="0 0 0 10" ></TextBox>
+			<TextBox Text="{Binding RegVM.CurrentUser.Patronymic}" Watermark="Отчество" Width="360" FontSize="13" Margin="0 0 0 25" ></TextBox>
 			<TextBlock Margin="0 0 0 10" FontFamily="Roboto" FontSize="14">Дата рождения:</TextBlock>
 			<TextBlock Margin="0 0 0 10" FontFamily="Roboto" FontSize="14">Дата рождения:</TextBlock>
 			<StackPanel Spacing="10" Orientation="Horizontal" HorizontalAlignment="Center">
 			<StackPanel Spacing="10" Orientation="Horizontal" HorizontalAlignment="Center">
-				<DatePicker Width="360" CornerRadius="8" Background="#F8FDFF" BorderBrush="#008BC7" BorderThickness="2" FontFamily="Roboto"></DatePicker>
+				<DatePicker SelectedDate="{Binding RegVM.Birthday}" Width="360" CornerRadius="8" Background="#F8FDFF" BorderBrush="#008BC7" BorderThickness="2" FontFamily="Roboto"></DatePicker>
 			</StackPanel>
 			</StackPanel>
-			<TextBox Watermark="Элетронная почта" Width="360" FontSize="13" Margin="0 25 0 10" ></TextBox>
-			<TextBox Watermark="Номер телефона" Width="360" FontSize="13" Margin="0 0 0 25" ></TextBox>
-			<Button HorizontalAlignment="Center" Margin="0 20 0 10" Width="230" Height="45" CornerRadius="10" Background="#38BFF2" Command="{Binding LoadLoginView}">
+			<TextBox Text="{Binding RegVM.CurrentUser.Email}" Watermark="Элетронная почта" Width="360" FontSize="13" Margin="0 25 0 10" ></TextBox>
+			<TextBox Text="{Binding RegVM.CurrentUser.Phonenumber}" Watermark="Номер телефона" Width="360" FontSize="13" Margin="0 0 0 25" ></TextBox>
+			<Button HorizontalAlignment="Center" Margin="0 20 0 10" Width="230" Height="45" CornerRadius="10" Background="#38BFF2" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveData}">
 				<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Roboto" FontSize="16" FontWeight="DemiBold" Foreground="White">Зарегистироваться</TextBlock>
 				<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Roboto" FontSize="16" FontWeight="DemiBold" Foreground="White">Зарегистироваться</TextBlock>
 			</Button>
 			</Button>
 			<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
 			<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">