@using Hcs.WebApp.Services
@inject DialogService DialogService
@inject FileToParseService FileToParseService
@errorMessage
@code {
enum UploadState
{
Idle,
InProgress,
Completed
}
RadzenUpload upload;
UploadState state;
int progress;
bool hasError;
string errorMessage;
int? fileToParseId;
[Parameter]
public required string UploaderId { get; set; }
void Upload()
{
state = UploadState.InProgress;
hasError = false;
upload.Upload();
}
void Close()
{
DialogService.Close(fileToParseId);
}
void OnProgress(UploadProgressArgs args)
{
progress = args.Progress;
}
async Task OnCompleteAsync(UploadCompleteEventArgs args)
{
try
{
var root = args.JsonResponse.RootElement;
var fileToParse = await FileToParseService.AddFileToParseAsync(
root.GetProperty("Path").GetString(),
root.GetProperty("FileName").GetString(),
UploaderId,
DateTime.Now);
fileToParseId = fileToParse.Id;
}
catch (Exception e)
{
hasError = true;
errorMessage = e.Message;
}
state = hasError ? UploadState.Idle : UploadState.Completed;
}
}