using Microsoft.AspNetCore.Components; using ProjetBlazor.Services; using ProjetBlazor.Modeles; using Microsoft.AspNetCore.Components.Forms; using ProjetBlazor.Factories; namespace ProjetBlazor.Pages { public partial class Edit { [Parameter] public int Id { get; set; } private MusiqueModel musiqueModele = new MusiqueModel(); [Inject] public IWebHostEnvironment WebHostEnvironment { get; set; } [Inject] public NavigationManager NavigationManager { get; set; } [Inject] public IDataService DataService { get; set; } private async void HandleValidSubmit() { await DataService.Update(Id,musiqueModele); NavigationManager.NavigateTo(""); } private async Task LoadImage(InputFileChangeEventArgs e) { // Set the content of the image to the model using (var memoryStream = new MemoryStream()) { await e.File.OpenReadStream().CopyToAsync(memoryStream); musiqueModele.image = memoryStream.ToArray(); } } protected override async Task OnInitializedAsync() { var musique = await DataService.GetById(Id); /* var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.png"); if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{musiqueModele.titre}.png")) { fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/{item.titre}.png"); }*/ var file = await File.ReadAllBytesAsync("https://localhost:7234/images/default.png"); if (!musique.image.Equals("default.png")){ file = await File.ReadAllBytesAsync("https://localhost:7234/images/{musique.image}"); } // Set the model with the item musiqueModele = MusiqueFactory.ToModel(musique, file); } } }