Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion BlazorLearnWebApp/Components/Components/UploadAvatar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public UserEntity? UserEntity { get; set; }

private string? _uploadPath;
private UploadFile? _arg;

private async Task OnAvatarUpload(UploadFile arg)
{
Expand Down Expand Up @@ -44,6 +45,7 @@
await arg.SaveToFileAsync(Path.Combine(WebHostEnvironment.WebRootPath, _uploadPath));

arg.PrevUrl = _uploadPath;
_arg = arg;//save the arg
}

public async Task OnClose(DialogResult result)
Expand All @@ -57,6 +59,14 @@
UserEntity!.AvatarPath = _uploadPath;
await UserEntity.SaveAsync();
}
else
{
if (!string.IsNullOrEmpty(_uploadPath) && _arg != null)
{
//delete new but cancelled avatar
File.Delete(Path.Combine(WebHostEnvironment.WebRootPath, _uploadPath));
}
}
}

}
}