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.
59 lines
1.7 KiB
59 lines
1.7 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 item = 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");
|
|
}
|
|
|
|
// Set the model with the item
|
|
musiqueModele = MusiqueFactory.ToModel(item, fileContent);
|
|
}
|
|
}
|
|
}
|