|
|
|
@ -7,100 +7,31 @@ namespace ProjetBlazor.Pages
|
|
|
|
|
{
|
|
|
|
|
public partial class AddMusique
|
|
|
|
|
{
|
|
|
|
|
private MusiqueModel musiqueModele = new MusiqueModel();
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IWebHostEnvironment WebHostEnvironment { get; set; }
|
|
|
|
|
private MusiqueModel musiqueModel = new MusiqueModel();
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
|
[Inject]
|
|
|
|
|
public IDataService DataService { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IDataService DataService { get; set; }
|
|
|
|
|
[Inject]
|
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
|
|
|
|
|
|
private async void HandleValidSubmit()
|
|
|
|
|
{
|
|
|
|
|
var currentData = await LocalStorage.GetItemAsync<List<Item>>("data");
|
|
|
|
|
|
|
|
|
|
// Simulate the Id
|
|
|
|
|
itemModel.Id = currentData.Max(s => s.Id) + 1;
|
|
|
|
|
|
|
|
|
|
// Add the item to the current data
|
|
|
|
|
currentData.Add(new Item
|
|
|
|
|
{
|
|
|
|
|
Id = MusiqueModel.id,
|
|
|
|
|
Titre = MusiqueModel.DisplayName,
|
|
|
|
|
Auteur = MusiqueModel.Name,
|
|
|
|
|
Duree = MusiqueModel.RepairWith,
|
|
|
|
|
Genre = MusiqueModel.EnchantCategories,
|
|
|
|
|
Image = MusiqueModel.MaxDurability,
|
|
|
|
|
Date =
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Save the image
|
|
|
|
|
var imagePathInfo = new DirectoryInfo($"{WebHostEnvironment.WebRootPath}/images");
|
|
|
|
|
|
|
|
|
|
// Check if the folder "images" exist
|
|
|
|
|
if (!imagePathInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
imagePathInfo.Create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine the image name
|
|
|
|
|
var fileName = new FileInfo($"{imagePathInfo}/{itemModel.Name}.png");
|
|
|
|
|
|
|
|
|
|
// Write the file content
|
|
|
|
|
await File.WriteAllBytesAsync(fileName.FullName, itemModel.ImageContent);
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
|
await LocalStorage.SetItemAsync("data", currentData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
itemModel.ImageContent = memoryStream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnchantCategoriesChange(string item, object checkedValue)
|
|
|
|
|
{
|
|
|
|
|
if ((bool)checkedValue)
|
|
|
|
|
private async void HandleValidSubmit()
|
|
|
|
|
{
|
|
|
|
|
if (!itemModel.EnchantCategories.Contains(item))
|
|
|
|
|
{
|
|
|
|
|
itemModel.EnchantCategories.Add(item);
|
|
|
|
|
}
|
|
|
|
|
await DataService.Add(musiqueModel);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
NavigationManager.NavigateTo("MusiqueListe");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemModel.EnchantCategories.Contains(item))
|
|
|
|
|
private async Task LoadImage(InputFileChangeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
itemModel.EnchantCategories.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRepairWithChange(string item, object checkedValue)
|
|
|
|
|
{
|
|
|
|
|
if ((bool)checkedValue)
|
|
|
|
|
{
|
|
|
|
|
if (!itemModel.RepairWith.Contains(item))
|
|
|
|
|
// Set the content of the image to the model
|
|
|
|
|
using (var memoryStream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
itemModel.RepairWith.Add(item);
|
|
|
|
|
await e.File.OpenReadStream().CopyToAsync(memoryStream);
|
|
|
|
|
musiqueModel.image = memoryStream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemModel.RepairWith.Contains(item))
|
|
|
|
|
{
|
|
|
|
|
itemModel.RepairWith.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|