Darius BERTRAND 3 years ago
parent 5e7579e408
commit e1dfd210bf

@ -5,35 +5,35 @@
<h3>AddMusique</h3> <h3>AddMusique</h3>
<EditForm Model=@musiqueModele OnValidSubmit="@HandleValidSubmit"> <EditForm Model=@musiqueModel OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator /> <DataAnnotationsValidator />
<ValidationSummary /> <ValidationSummary />
<p> <p>
<label for="titre"> <label for="titre">
Display Titre: Display Titre:
<InputText id="titre" @bind-Value="musiqueModele.titre" /> <InputText id="titre" @bind-Value="musiqueModel.titre" />
</label> </label>
</p> </p>
<p> <p>
<label for="auteur"> <label for="auteur">
Display Auteur: Display Auteur:
<InputText id="auteur" @bind-Value="musiqueModele.auteur" /> <InputText id="auteur" @bind-Value="musiqueModel.auteur" />
</label> </label>
</p> </p>
<p> <p>
<label for="duree"> <label for="duree">
Display Durée: Display Durée:
<InputNumber id="duree" @bind-Value="musiqueModele.duree" /> <InputNumber id="duree" @bind-Value="musiqueModel.duree" />
</label> </label>
</p> </p>
<p> <p>
<label for="genre"> <label for="genre">
Display Genre: Display Genre:
<InputText id="genre" @bind-Value="musiqueModele.genre" /> <InputText id="genre" @bind-Value="musiqueModel.genre" />
</label> </label>
</p> </p>
@ -46,13 +46,13 @@
<label for="display-name"> <label for="display-name">
Display Name Image : Display Name Image :
<InputText id="display-name" @bind-Value="musiqueModele.DisplayName" /> <InputText id="display-name" @bind-Value="musiqueModel.DisplayName" />
</label> </label>
<p> <p>
<label for="date"> <label for="date">
Display Date: Display Date:
<InputDate id="date" @bind-Value="musiqueModele.date" /> <InputDate id="date" @bind-Value="musiqueModel.date" />
</label> </label>
</p> </p>

@ -7,100 +7,31 @@ namespace ProjetBlazor.Pages
{ {
public partial class AddMusique public partial class AddMusique
{ {
private MusiqueModel musiqueModele = new MusiqueModel();
[Inject] private MusiqueModel musiqueModel = new MusiqueModel();
public IWebHostEnvironment WebHostEnvironment { get; set; }
[Inject] [Inject]
public NavigationManager NavigationManager { get; set; } public IDataService DataService { get; set; }
[Inject] [Inject]
public IDataService DataService { get; set; } public NavigationManager NavigationManager { get; set; }
private async void HandleValidSubmit() 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)
{ {
if (!itemModel.EnchantCategories.Contains(item)) await DataService.Add(musiqueModel);
{
itemModel.EnchantCategories.Add(item);
}
return; NavigationManager.NavigateTo("MusiqueListe");
} }
if (itemModel.EnchantCategories.Contains(item)) private async Task LoadImage(InputFileChangeEventArgs e)
{ {
itemModel.EnchantCategories.Remove(item); // Set the content of the image to the model
} using (var memoryStream = new MemoryStream())
}
private void OnRepairWithChange(string item, object checkedValue)
{
if ((bool)checkedValue)
{
if (!itemModel.RepairWith.Contains(item))
{ {
itemModel.RepairWith.Add(item); await e.File.OpenReadStream().CopyToAsync(memoryStream);
musiqueModel.image = memoryStream.ToArray();
} }
return;
} }
if (itemModel.RepairWith.Contains(item))
{
itemModel.RepairWith.Remove(item);
}
} }
} }
}

Loading…
Cancel
Save