@page "/Settings/Archives" @inject StorageLocationService StorageLocationService @inject IMessageService MessageService @inject ILogger Logger @attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@code { Settings Settings = SettingService.GetSettings(); ICollection StorageLocations; string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); protected override async Task OnInitializedAsync() { Settings = SettingService.GetSettings(); StorageLocations = await StorageLocationService.GetAsync(l => l.Type == SDK.Enums.StorageLocationType.Archive); } async Task Save() { try { SettingService.SaveSettings(Settings); foreach (var storageLocation in StorageLocations) { if (!StorageLocations.Any(l => l.Default)) storageLocation.Default = true; if (storageLocation.Id != Guid.Empty) await StorageLocationService.UpdateAsync(storageLocation); else await StorageLocationService.AddAsync(storageLocation); } MessageService.Success("Settings saved!"); } catch (Exception ex) { MessageService.Error("An unknown error occurred."); Logger.LogError(ex, "An unknown error occurred."); } } void OnPathSelected(StorageLocation storageLocation, string path) { var appPath = Directory.GetCurrentDirectory(); if (path != null && path.StartsWith(appPath)) path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar); storageLocation.Path = path; } async Task AddStorageLocation() { StorageLocations.Add(new StorageLocation()); StateHasChanged(); } async Task RemoveStorageLocation(StorageLocation storageLocation) { StorageLocations.Remove(storageLocation); } }