using System; using System.Collections.Generic; using System.Linq; using Avalonia.Controls; using AvaloniaApplication3.Models; using Microsoft.EntityFrameworkCore; using ReactiveUI; namespace AvaloniaApplication3.ViewModels { public class PersonalAccountViewModel : ViewModelBase { User? currentUser; UsersLogin? user; TestDataBaseCheskinaContext db = new TestDataBaseCheskinaContext(); public PersonalAccountViewModel(User? currentUser) { this.currentUser = currentUser; GetData(); } private void GetData() { user = db.UsersLogins.Include(u => u.IdUserNavigation).FirstOrDefault(x => x.IdUser == currentUser.IdUser); Name = user.IdUserNavigation.Name; Surname = user.IdUserNavigation.Surname; Patronumic = user.IdUserNavigation.Patronymic; Login = user.Login; Password = user.Password; } private string? name; private string? surname; private string? patronumic; private string? login; private string? password; private string? newPassword; private string? newPasswordAgain; private string message = ""; private bool isChangedPass = false; public void SaveChanges() { if (Name != null && Name !="" && Surname != null && Surname != "" && Patronumic != null && Patronumic != "" && Login != null && Login != "") { user.IdUserNavigation.Name = Name; user.IdUserNavigation.Surname = Surname; user.IdUserNavigation.Patronymic = Patronumic; user.Login = Login; if (IsChangedPass) { if (NewPassword != NewPasswordAgain) Message = "Пароли не совпадают"; else if (NewPassword != null && NewPassword != "" && NewPasswordAgain != null && NewPasswordAgain != "") Password = NewPasswordAgain; else Message = "Заполнены не все данные"; } user.Password = Password; db.SaveChanges(); } else Message = "Заполнены не все данные"; } public User? CurrentUser { get => currentUser; set => currentUser = value; } public string? Name { get => name; set => name = value; } public string? Surname { get => surname; set => surname = value; } public string? Patronumic { get => patronumic; set => patronumic = value; } public string? Login { get => login; set => login = value; } public string? Password { get => password; set => password = value; } public string? NewPassword { get => newPassword; set => newPassword = value; } public string? NewPasswordAgain { get => newPasswordAgain; set => newPasswordAgain = value; } public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); } public bool IsChangedPass { get => isChangedPass; set => this.RaiseAndSetIfChanged(ref isChangedPass, value); } } }