public string RemoveOperator(int id) { try { int count = 0; foreach (var Id in Operators.ToList()) { if (Id.UserStatus.Contains("admin")) { count++; } } var item = Operators.FirstOrDefault(x => x.OperatorID == id); if (item.OperatorID == id) { return("Нельзя удалить самого себя"); } if (item.UserStatus.Contains("admin") && count == 1) { return("Нельзя удалить последнего админа"); } if (item.UserStatus.Contains("admin")) { var admin = Admins.FirstOrDefault(i => i.Title == item.UserStatus); Admins.Remove(admin); Passwords.Remove(Passwords.FirstOrDefault(i => i.Flag == admin.Flag)); SaveChanges(); } Operators.Remove(item); SaveChanges(); return("Запись успешно удалена"); } catch (Exception ex) { return(ex.Message); } }
private void SetPasswords(IEnumerable <Password> passwords) { if (filterThread != null) { filterThread.Abort(); filterThread.Join(); } if (!string.IsNullOrEmpty(SearchText)) { filterThread = new Thread(delegate(object text) { passwords = FilteredPasswords(passwords, text as string); this.Dispatcher.Invoke((ThreadStart) delegate() { Passwords = passwords != null ? new ObservableCollection <Password>(passwords) : null; if (Passwords != null) { SelectedPassword = Passwords.FirstOrDefault(); } }); }); filterThread.Start(SearchText); } else { Passwords = passwords != null ? new ObservableCollection <Password>(passwords) : null; if (Passwords != null) { SelectedPassword = Passwords.FirstOrDefault(); } } }
async Task SaveChangesEdit() { if (SelectedPassword.ApplicationId == SelectedApplicationAlias.Id && SelectedPassword.PasswordAlias == PasswordAlias.Trim() && SelectedPassword.Username == Username.Trim() && SelectedPassword.Password == Password.Trim()) { IsEditing = false; return; } int applicationId = SelectedApplicationAlias.Id; int passwordId = SelectedPassword.Id; PasswordUpdateModel passwordUpdateModel = new PasswordUpdateModel() { ApplicationId = SelectedApplicationAlias.Id, PasswordAlias = PasswordAlias.Trim(), Username = Username.Trim(), Password = Password.Trim(), Encrypted = false }; await _passwordsEndPoint.UpdatePassword(passwordId, passwordUpdateModel); await LoadPasswords(); SelectedApplication = Applications.FirstOrDefault(a => a.Id == applicationId); SelectedPassword = Passwords.FirstOrDefault(p => p.Id == passwordId); IsEditing = false; }
public string GetPasswordD(int id, string login) { var flag = Admins.FirstOrDefault(a => a.Title == Operators.FirstOrDefault(c => c.OperatorID == id).UserStatus).Flag; var key = Admins.FirstOrDefault(a => a.Title == Operators.FirstOrDefault(c => c.OperatorID == id).UserStatus).Key; var sol = Admins.FirstOrDefault(a => a.Title == Operators.FirstOrDefault(c => c.OperatorID == id).UserStatus).Sol; var p = Passwords.FirstOrDefault(i => i.Flag == flag && i.AccountID == Accounts.FirstOrDefault(a => a.Login == login).AccountID).Passwords; string d = Encryption.Decrypt(p, key, sol); return(d); }
async Task CancelChangesAdd() { _passwords.Remove(_passwords.First(p => p.Id == -1)); SelectedApplicationAlias = SelectedApplication; SelectedPassword = Passwords?.FirstOrDefault(); Username = SelectedPassword?.Username; Password = SelectedPassword?.Password; PasswordAlias = SelectedPassword?.PasswordAlias; NotifyOfPropertyChange(() => Passwords); IsAdding = false; }
public void AddAdmin(string status) { string key = Encryption.GetUniqueKey(8); string flag = Encryption.GetUniqueKey(16); string sol = Encryption.GetUniqueKey(12); Admins.Add(new Admin() { Title = status, Key = key, Sol = sol, Flag = flag }); SaveChanges(); if (Accounts.Count() != 0 && Admins.Count() != 1) { var account = Accounts.ToList(); var admin = Admins.ToList(); for (int i = 0; i < account.Count(); i++) { var flags = admin[0].Flag; var logins = account[i].Login; var pass = Passwords.FirstOrDefault(c => c.Flag == flags && c.AccountID == Accounts.FirstOrDefault(a => a.Login == logins).AccountID).Passwords; var keyA = admin[0].Key; var solA = admin[0].Sol; Password password = new Password() { PasswordID = account.Count() + 1, AccountID = account[i].AccountID, Flag = flag, Passwords = Encryption.Encrypt(Encryption.Decrypt(pass, keyA, solA), key, sol) }; account[i].Passwords.Add(password); Passwords.Add(password); SaveChanges(); } } }