123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using AvaloniaApplication5.Models;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- namespace AvaloniaApplication5.ViewModels
- {
- public class PageUserCabinetViewModel : ReactiveObject
- {
- Logintable? currentUser;
- _1234Context dBConnect;
- string oldPass;
- public PageUserCabinetViewModel(_1234Context dBConnect, int idUser)
- {
- this.dBConnect = dBConnect;
- CurrentUser = dBConnect.Logintables.Include(x=>x.IdRoleNavigation).Include(x=>x.User.IdGenderNavigation).FirstOrDefault(x => x.Id == idUser);
- oldPass = currentUser.Password;
- }
- public PageUserCabinetViewModel(_1234Context dBConnect)
- {
- this.dBConnect = dBConnect;
- int maxid = dBConnect.Logintables.Select(x => x.Id).Max();
- currentUser = new Logintable() { User = new User() { IdLogin = ++maxid }, IdRole =2 };
- changePass = true;//÷òîáû èçìåíåíèå ïàðîëÿ áûëî àêèâíî
- }
- public Logintable? CurrentUser { get => currentUser; set => currentUser = value; }
- public List<Gender> Genders => dBConnect.Genders.ToList();
- public string DR { get => CurrentUser.User.BirthDate.ToString(); set => CurrentUser.User.BirthDate = DateTime.Parse(value); }
- public bool ChangePass { get => changePass; set =>this.RaiseAndSetIfChanged(ref changePass, value); }
- public string PasswordMatch { get => passwordMatch; set => passwordMatch = value; }
- public string Message { get => message; set =>this.RaiseAndSetIfChanged(ref message,value); }
- bool changePass = false;
- string passwordMatch;
- string message;
- public void SaveData()
- {
- if (CurrentUser.Password == null || CurrentUser.Password =="") CurrentUser.Password = oldPass;
- if (changePass==(currentUser.Password == PasswordMatch))
- {
- if (currentUser.Id == 0) dBConnect.Add(currentUser);
- dBConnect.SaveChanges();
- Message = "Ñîõðàíåíî óñïåøíî";
- }
- else
- {
- Message = "Ïàðîëè íå ñîâïàäàþò";
- }
- }
-
- }
- }
|