public void SaveChanges() { try { var canSave = AccountViewModels.All(vm => vm.CanSave()); if (!canSave) { DialogService.Error("Not all accounts are valid. Account Name is required."); return; } var duplicate = AccountViewModels.GroupBy(vm => vm.AccountName).Any(grp => grp.Count() > 1); if (duplicate) { DialogService.Error("Duplicate account names are not allowed."); return; } string encrypt(string text) => CryptoService.Encrypt(StorageService.GetSecretKey(Password), text); foreach (var vm in AccountViewModels) { var model = vm.ViewModelToModel(encrypt); StorageService.UpsertAccount(Password, model); vm.OnPostSave(); } Status = "Accounts saved..."; } catch (Exception e) { DialogService.Exception(e); } }