You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.0 KiB
64 lines
2.0 KiB
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);
|
|
}
|
|
}
|
|
}
|