@inject MesaFabApprovalAuthStateProvider authStateProvider @inject NavigationManager navigationManager @inject IPCRBService pcrbService @inject ISnackbar snackbar @if (addFileInProcess) { Processing } else { Add File } @if (processing) { Processing } else { Submit } Cancel @code { [CascadingParameter] MudDialogInstance MudDialog { get; set; } [Parameter] public int planNumber { get; set; } = 0; [Parameter] public int step { get; set; } = 0; private string[] errors = { }; private string fileName = ""; private IBrowserFile? file = null; private bool addFileInProcess = false; private bool processing = false; protected override async Task OnParametersSetAsync() { if (planNumber <= 0) { snackbar.Add($"{planNumber} is not a valid PCRB plan#", Severity.Error); MudDialog.Close(DialogResult.Cancel()); } if (step <= 0) { snackbar.Add($"{step} is not a valid PCRB stage#", Severity.Error); MudDialog.Close(DialogResult.Cancel()); } if (authStateProvider.CurrentUser is null) { await authStateProvider.Logout(); navigationManager.NavigateTo("login"); } } private void AddFile(IBrowserFile newFile) { addFileInProcess = true; file = newFile; fileName = newFile.Name; addFileInProcess = false; } private async Task Submit() { processing = true; try { if (authStateProvider.CurrentUser is null) { await authStateProvider.Logout(); navigationManager.NavigateTo("login"); return; } if (string.IsNullOrWhiteSpace(fileName)) throw new Exception("file name missing"); if (file is null) throw new Exception("file is missing"); PCRBAttachment attachment = new() { Step = step, UploadDateTime = DateTime.Now, UploadedByID = authStateProvider.CurrentUser.UserID, PlanNumber = planNumber, File = file, FileName = fileName }; await pcrbService.UploadAttachment(attachment); processing = false; MudDialog.Close(DialogResult.Ok(attachment)); } catch (Exception ex) { snackbar.Add($"Unable to save document, because {ex.Message}", Severity.Error); processing = false; } } private void Cancel() { MudDialog.Close(DialogResult.Cancel()); } }