using LogoForceTestApp.Modules.MainModule.Models;
using Prism.Commands;
using Prism.Mvvm;
using Repository;
using Repository.Entiies;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LogoForceTestApp.Modules.MainModule.ViewModels
{
    public class AccountPageViewModel: BindableBase
    {
        IRepository _repository;
        public string IdAcc { get; set; }
        public string ChangeP { get; set; }
        public DelegateCommand PasswordCommand { get; set; }
        public AccountPageViewModel(IRepository repository) 
        {
            _repository = repository;
            PasswordCommand = new DelegateCommand(ChangePassword);
        }

        private void ChangePassword()
        {
            System.Windows.Forms.DialogResult digres = MessageBox.Show("确认是否修改密码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            if (digres == System.Windows.Forms.DialogResult.OK)
            {
                var change= _repository.GetFirstDefault<Account>(c => c.AccountID == IdAcc);//数据库查
                change.ChangePassword = ChangeP;//改
                _repository.Update(change);//更新  
            }
            else
            {
                ChangeP = string.Empty;
            }
        }
    }
}