protected override async Task OnInitializedAsync() { try { _folders = await FolderService.GetFoldersAsync(PageState.Site.SiteId); if (PageState.QueryString.ContainsKey("id")) { _folderId = Int32.Parse(PageState.QueryString["id"]); Folder folder = await FolderService.GetFolderAsync(_folderId); if (folder != null) { _parentId = folder.ParentId ?? -1; _name = folder.Name; _isSystem = folder.IsSystem; _permissions = folder.Permissions; _createdBy = folder.CreatedBy; _createdOn = folder.CreatedOn; _modifiedBy = folder.ModifiedBy; _modifiedOn = folder.ModifiedOn; } } else { _parentId = _folders[0].FolderId; _permissions = string.Empty; } } catch (Exception ex) { await logger.LogError(ex, "Error Loading Folder {FolderId} {Error}", _folderId, ex.Message); AddModuleMessage("Error Loading Folder", MessageType.Error); } }
private async Task SaveFolder() { if (_name == string.Empty || _parentId == -1) { AddModuleMessage("Folders Must Have A Parent And A Name", MessageType.Warning); return; } if (!_name.IsPathOrFileValid()) { AddModuleMessage("Folder Name Not Valid.", MessageType.Warning); return; } try { Folder folder; if (_folderId != -1) { folder = await FolderService.GetFolderAsync(_folderId); } else { folder = new Folder(); } folder.SiteId = PageState.Site.SiteId; if (_parentId == -1) { folder.ParentId = null; } else { folder.ParentId = _parentId; } folder.Name = _name; folder.IsSystem = _isSystem; folder.Permissions = _permissionGrid.GetPermissions(); if (_folderId != -1) { folder = await FolderService.UpdateFolderAsync(folder); } else { folder = await FolderService.AddFolderAsync(folder); } if (folder != null) { await FolderService.UpdateFolderOrderAsync(folder.SiteId, folder.FolderId, folder.ParentId); await logger.LogInformation("Folder Saved {Folder}", folder); NavigationManager.NavigateTo(NavigateUrl()); } else { AddModuleMessage("An Error Was Encountered Saving The Folder", MessageType.Error); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving Folder {FolderId} {Error}", _folderId, ex.Message); AddModuleMessage("Error Saving Module", MessageType.Error); } }