public async Task <IActionResult> Create(AdminNodeEditViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Forbid()); } var adminMenuList = await _adminMenuService.LoadAdminMenuListAsync(); var adminMenu = _adminMenuService.GetAdminMenuById(adminMenuList, model.AdminMenuId); if (adminMenu == null) { return(NotFound()); } var treeNode = _factories.FirstOrDefault(x => x.Name == model.AdminNodeType)?.Create(); if (treeNode == null) { return(NotFound()); } dynamic editor = await _displayManager.UpdateEditorAsync(treeNode, updater : _updateModelAccessor.ModelUpdater, isNew : true); editor.TreeNode = treeNode; if (ModelState.IsValid) { treeNode.UniqueId = model.AdminNodeId; adminMenu.MenuItems.Add(treeNode); await _adminMenuService.SaveAsync(adminMenu); _notifier.Success(H["Admin node added successfully"]); return(RedirectToAction("List", new { id = model.AdminMenuId })); } model.Editor = editor; // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Edit(AdminNodeEditViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Unauthorized()); } var adminMenuList = await _mainMenuService.LoadMainMenuListAsync(); var adminMenu = _mainMenuService.GetMainMenuById(adminMenuList, model.AdminMenuId); if (adminMenu == null) { return(NotFound()); } var treeNode = adminMenu.GetMenuItemById(model.AdminNodeId); if (treeNode == null) { return(NotFound()); } var editor = await _displayManager.UpdateEditorAsync(treeNode, updater : this, isNew : false); if (ModelState.IsValid) { treeNode.Priority = model.Priority; treeNode.Position = model.Position; await _mainMenuService.SaveAsync(adminMenu); _notifier.Success(H["Admin node updated successfully"]); return(RedirectToAction(nameof(List), new { id = model.AdminMenuId })); } _notifier.Error(H["The admin node has validation errors"]); model.Editor = editor; // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Edit(string id, string treeNodeId) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return(Forbid()); } var adminMenuList = await _adminMenuService.GetAdminMenuListAsync(); var adminMenu = _adminMenuService.GetAdminMenuById(adminMenuList, id); if (adminMenu == null) { return(NotFound()); } var treeNode = adminMenu.GetMenuItemById(treeNodeId); if (treeNode == null) { return(NotFound()); } var model = new AdminNodeEditViewModel { AdminMenuId = id, AdminNode = treeNode, AdminNodeId = treeNode.UniqueId, AdminNodeType = treeNode.GetType().Name, Priority = treeNode.Priority, Position = treeNode.Position, Editor = await _displayManager.BuildEditorAsync(treeNode, updater : _updateModelAccessor.ModelUpdater, isNew : false) }; model.Editor.TreeNode = treeNode; return(View(model)); }