|
@@ -1,35 +1,53 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
+using Avalonia.Controls.ApplicationLifetimes;
|
|
|
+using System.Threading.Tasks;
|
|
|
using Avalonia.Media;
|
|
|
+using Avalonia.Media.Imaging;
|
|
|
+using Avalonia.Platform.Storage;
|
|
|
using AvaloniaHomeTry.Models;
|
|
|
using Microsoft.Win32;
|
|
|
using ReactiveUI;
|
|
|
+using Avalonia;
|
|
|
+using Avalonia.Controls.Platform;
|
|
|
|
|
|
namespace AvaloniaHomeTry.ViewModels
|
|
|
{
|
|
|
- public class RegistrationPageViewModel : ViewModelBase
|
|
|
- {
|
|
|
- UsersTable? currentUser;
|
|
|
-
|
|
|
- Gender? genderId;
|
|
|
- List<Gender> genders;
|
|
|
+ public class RegistrationPageViewModel : ViewModelBase
|
|
|
+ {
|
|
|
|
|
|
- string login;
|
|
|
- string password;
|
|
|
- string surname;
|
|
|
- string name;
|
|
|
- string patronymic;
|
|
|
- DateTime dob = DateTime.UtcNow;
|
|
|
+ UsersTable? currentUser;
|
|
|
+
|
|
|
+ List<UsersTable> mainUsers;
|
|
|
+
|
|
|
+ List<UsersTable> secondUsers;
|
|
|
+
|
|
|
+ Gender? genderId;
|
|
|
+ List<Gender> genders;
|
|
|
+
|
|
|
+ string login;
|
|
|
+ string password;
|
|
|
+ string surname;
|
|
|
+ string name;
|
|
|
+ string patronymic;
|
|
|
+ DateTime dob = DateTime.UtcNow;
|
|
|
private string message;
|
|
|
+ Bitmap? userImage;
|
|
|
|
|
|
|
|
|
public RegistrationPageViewModel()
|
|
|
- {
|
|
|
- this.genders = db.Genders.ToList();
|
|
|
- }
|
|
|
+ {
|
|
|
+ this.genders = db.Genders.ToList();
|
|
|
+ }
|
|
|
+ public RegistrationPageViewModel(int idUser)
|
|
|
+ {
|
|
|
+ UserImage = CurrentUser.Image != null ? new Bitmap(new MemoryStream(CurrentUser.Image)) : new Bitmap("D:\\avaloniax\\AvaloniaHomeTry\\Assets\\background.jpg");
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
public Gender? GenderId { get => genderId; set => this.RaiseAndSetIfChanged(ref genderId, value); }
|
|
|
public List<Gender> Genders { get => genders; set => this.RaiseAndSetIfChanged(ref genders, value); }
|
|
|
public string Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }
|
|
@@ -39,6 +57,10 @@ namespace AvaloniaHomeTry.ViewModels
|
|
|
public string Patronymic { get => patronymic; set => this.RaiseAndSetIfChanged(ref patronymic, value); }
|
|
|
public DateTime Dob { get => dob; set => this.RaiseAndSetIfChanged(ref dob, value); }
|
|
|
public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
|
|
|
+ public Bitmap? UserImage { get => userImage; set => this.RaiseAndSetIfChanged(ref userImage, value); }
|
|
|
+ public UsersTable? CurrentUser { get => currentUser; set => this.RaiseAndSetIfChanged(ref currentUser, value); }
|
|
|
+ public List<UsersTable> MainUsers { get => mainUsers; set => this.RaiseAndSetIfChanged(ref mainUsers, value); }
|
|
|
+ public List<UsersTable> SecondUsers { get => secondUsers; set => this.RaiseAndSetIfChanged(ref secondUsers, value); }
|
|
|
|
|
|
public DateTimeOffset DateTimeOffset
|
|
|
{
|
|
@@ -51,7 +73,7 @@ namespace AvaloniaHomeTry.ViewModels
|
|
|
UsersTable flag = db.UsersTable.FirstOrDefault(x => x.Login == Login);
|
|
|
if (flag == null)
|
|
|
{
|
|
|
- currentUser = new UsersTable
|
|
|
+ CurrentUser = new UsersTable
|
|
|
{
|
|
|
Login = Login,
|
|
|
Password = Password,
|
|
@@ -60,13 +82,14 @@ namespace AvaloniaHomeTry.ViewModels
|
|
|
Patronymic = Patronymic,
|
|
|
Dataofbirth = Dob,
|
|
|
IdGender = genderId.Id,
|
|
|
- IdRole = 2
|
|
|
+ IdRole = 2
|
|
|
};
|
|
|
|
|
|
- db.UsersTable.Add(currentUser);
|
|
|
+ Image(CurrentUser.Id);
|
|
|
+ db.UsersTable.Add(CurrentUser);
|
|
|
db.SaveChanges();
|
|
|
- currentUser = db.UsersTable.FirstOrDefault(x => x.Login == Login);
|
|
|
- MainWindowViewModel.Self.UC = new UserPage(currentUser.Id);
|
|
|
+ CurrentUser = db.UsersTable.FirstOrDefault(x => x.Login == Login);
|
|
|
+ MainWindowViewModel.Self.UC = new UserPage(CurrentUser.Id);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -75,5 +98,31 @@ namespace AvaloniaHomeTry.ViewModels
|
|
|
}
|
|
|
|
|
|
public void Back() => MainWindowViewModel.Self.UC = new AuthPage();
|
|
|
+
|
|
|
+ public async Task Image(int id)
|
|
|
+ {
|
|
|
+ if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop ||
|
|
|
+ desktop.MainWindow?.StorageProvider is not { } provider)
|
|
|
+ throw new NullReferenceException("Missing StorageProvider instance.");
|
|
|
+ {
|
|
|
+ var files = await provider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
|
|
+ {
|
|
|
+ Title = "Âûáèðèòå ôàéë ñ èçîáðàæåíèåì: ",
|
|
|
+ AllowMultiple = false
|
|
|
+ });
|
|
|
+
|
|
|
+ await using var readStream = await files[0].OpenReadAsync();
|
|
|
+ byte[] buffer = new byte[10000000];
|
|
|
+ var bytes = readStream.ReadAtLeast(buffer, 1);
|
|
|
+ Array.Resize(ref buffer, bytes);
|
|
|
+ currentUser = db.UsersTable.FirstOrDefault(x => x.Id == id);
|
|
|
+ currentUser.Image = buffer;
|
|
|
+ UserImage = new Bitmap(new MemoryStream(currentUser.Image));
|
|
|
+ db.SaveChanges();
|
|
|
+ SecondUsers = db.UsersTable.ToList();
|
|
|
+ MainUsers = SecondUsers;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|