123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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); }
- }
- }
|