public UserViewModel() { List = new ObservableCollection <Model.Userr>(DataProvider.Ins.DB.Userrs);// hiển thị danh sách Role = new ObservableCollection <Model.UserRole>(DataProvider.Ins.DB.UserRoles); AddCommand = new RelayCommand <object>((p) => { if (SelectedRole == null) { return(false); } return(true); }, (p) => { var Userr = new Model.Userr() { DisplayName = DisplayName, Email = Email, Password = Password, IdRole = SelectedRole.Id }; DataProvider.Ins.DB.Userrs.Add(Userr); DataProvider.Ins.DB.SaveChanges(); List.Add(Userr); }); EditCommand = new RelayCommand <object>((p) => { if (SelectedRole == null || SelectedItem == null) { return(false); } return(true); }, (p) => { var user = DataProvider.Ins.DB.Userrs.Where(x => x.Id == SelectedItem.Id).SingleOrDefault();//lấy ra id tương ứng user.IdRole = SelectedRole.Id; DataProvider.Ins.DB.SaveChanges(); SelectedItem.IdRole = SelectedRole.Id; var userList = List.Where(x => x.Id == SelectedItem.Id).SingleOrDefault(); userList.IdRole = SelectedRole.Id; }); }
public FogetPassViewModel() { ReplaceCommand = new RelayCommand <UserControl>((p) => { return(true); // điều kiện để nhấn button }, (p) => { string passEncode = MD5Hash(Base64Encode(Password)); var Userr = new Model.Userr() { Email = Email, Password = passEncode, IdRole = 3 }; DataProvider.Ins.DB.Userrs.Add(Userr); DataProvider.Ins.DB.SaveChanges(); }); PasswordChangedCommand = new RelayCommand <PasswordBox>((p) => { return(true); }, (p) => { Password = p.Password; }); }
public RegisterViewModel() { PasswordChangedCommand = new RelayCommand <PasswordBox>((p) => { return(true); }, (p) => { Password = p.Password; }); AddCommand = new RelayCommand <object>((p) => { return(true); // điều kiện để nhấn button }, (p) => { string passEncode = MD5Hash(Base64Encode(Password)); var Userr = new Model.Userr() { DisplayName = DisplayName, Email = Email, Password = passEncode, IdRole = 3 }; DataProvider.Ins.DB.Userrs.Add(Userr); DataProvider.Ins.DB.SaveChanges(); }); }