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.
127 lines
3.6 KiB
127 lines
3.6 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; }
|
|
|
|
/*
|
|
[Inject]
|
|
public NavigationManager NavigationManager { get; set; }
|
|
*/
|
|
|
|
/*
|
|
[Inject]
|
|
public IWebHostEnvironment WebHostEnvironment { get; set; }
|
|
*/
|
|
/*
|
|
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/{itemModel.Name}.png"))
|
|
{
|
|
fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/{item.Name}.png");
|
|
}
|
|
|
|
// Set the model with the item
|
|
itemModel = ItemFactory.ToModel(item, fileContent);
|
|
}
|
|
|
|
private async void HandleValidSubmit()
|
|
{
|
|
await DataService.Update(Id, itemModel);
|
|
|
|
NavigationManager.NavigateTo("list");
|
|
}
|
|
|
|
private void OnEnchantCategoriesChange(string item, object checkedValue)
|
|
{
|
|
if ((bool)checkedValue)
|
|
{
|
|
if (!itemModel.EnchantCategories.Contains(item))
|
|
{
|
|
itemModel.EnchantCategories.Add(item);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (itemModel.EnchantCategories.Contains(item))
|
|
{
|
|
itemModel.EnchantCategories.Remove(item);
|
|
}
|
|
}
|
|
|
|
private void OnRepairWithChange(string item, object checkedValue)
|
|
{
|
|
if ((bool)checkedValue)
|
|
{
|
|
if (!itemModel.RepairWith.Contains(item))
|
|
{
|
|
itemModel.RepairWith.Add(item);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (itemModel.RepairWith.Contains(item))
|
|
{
|
|
itemModel.RepairWith.Remove(item);
|
|
}
|
|
}
|
|
*/
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|