public JsonResult GetNodeItems(string parentId) { var treeNodes = new List <TreeNode>(); using (var masterPassword = SessionContext.GetMasterPassword()) { var currentVault = SessionContext.GetCurrentVaultName(); var vaultRepository = VaultRepositoryFactory.CreateInstance(); var vault = vaultRepository.GetVault(currentVault, masterPassword); if (parentId == "#") { //Root treeNodes.AddRange(vault.Groups.Select(group => CreateTreeNode(group.Id.ToString(), group.Name, parentId, group.Groups.Count > 0, true, group.Entries.Count))); } else { var vaultManipulator = VaultManipulatorFactory.CreateInstance(vault); var parentGroup = vaultManipulator.GetGroupById(Guid.Parse(parentId)); treeNodes.AddRange(parentGroup.Groups.Select(group => CreateTreeNode(group.Id.ToString(), group.Name, parentId, group.Groups.Count > 0, false, group.Entries.Count))); //treeNodes.AddRange(parentGroup.Entries.Select(entry => CreateTreeNode(entry.Id.ToString(), entry.Title, parentId, false, false, false))); } return(Json(treeNodes)); } }
public IActionResult Rename(VaultRenameViewModel model) { SyncContext.Lock(); try { using (var masterPassword = SessionContext.GetMasterPassword()) { if (ModelState.IsValid) { var vaultRepository = VaultRepositoryFactory.CreateInstance(); if (vaultRepository.VaultExists(model.NewVaultName)) { ModelState.AddModelError(nameof(model.NewVaultName), StringResources.VaultNameAlreadyExists); return(View(model)); } var currentVaultName = SessionContext.GetCurrentVaultName(); var vault = vaultRepository.GetVault(currentVaultName, masterPassword); vault.Name = model.NewVaultName; vaultRepository.SaveVault(vault, masterPassword); vaultRepository.DeleteVault(currentVaultName); SessionContext.SetCurrentVaultName(model.NewVaultName); return(RedirectToAction("Index", "VaultExplorer")); } else { return(View(model)); } } } finally { SyncContext.Release(); } }