Déblayage pour taff

blazor
Antoine JOURDAIN 1 year ago
parent 12ed75c767
commit 4398571200

@ -9,14 +9,15 @@ namespace adminBlazor.Factories
{ {
public static class VocListFactory public static class VocListFactory
{ {
public static VocabularyListModel ToModel(VocabularyList voc) public static VocabularyListModel ToModel(VocabularyList voc, byte[] imageContent)
{ {
return new VocabularyListModel return new VocabularyListModel
{ {
Id = voc.Id, Id = voc.Id,
Name = voc.Name, Name = voc.Name,
Image = voc.Image, Image = voc.Image,
Aut = voc.Aut Aut = voc.Aut,
ImageBase64 = string.IsNullOrWhiteSpace(voc.ImageBase64) ? Convert.ToBase64String(imageContent) : voc.ImageBase64
}; };
} }
@ -27,7 +28,8 @@ namespace adminBlazor.Factories
Id = voc.Id, Id = voc.Id,
Name = voc.Name, Name = voc.Name,
Image = voc.Image, Image = voc.Image,
Aut = voc.Aut Aut = voc.Aut,
ImageBase64 = voc.Image != null ? Convert.ToBase64String(voc.Image) : null
}; };
} }
public static void Update(VocabularyList item, VocabularyListModel voc) public static void Update(VocabularyList item, VocabularyListModel voc)
@ -35,8 +37,8 @@ namespace adminBlazor.Factories
if (!string.IsNullOrEmpty(voc.Name)) if (!string.IsNullOrEmpty(voc.Name))
item.Name = voc.Name; item.Name = voc.Name;
if (!string.IsNullOrEmpty(voc.Image)) if (voc.ImageBase64 != null && voc.Image != null)
item.Image = voc.Image; item.ImageBase64 = Convert.ToBase64String(voc.Image);
} }
} }

@ -5,8 +5,10 @@ namespace adminBlazor.Models
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Image { get; set; } public byte[] Image { get; set; }
public int? Aut { get; set; } public int? Aut { get; set; }
public string? ImageBase64 { get; set; }
} }
} }

@ -10,9 +10,11 @@ namespace adminBlazor.Models
public string Name { get; set; } public string Name { get; set; }
public string Image { get; set; } public byte[] Image { get; set; }
public int? Aut { get; set; } public int? Aut { get; set; }
public string ImageBase64 { get; set; }
} }
} }

@ -17,13 +17,5 @@
</label> </label>
</p> </p>
<p>
<label for="image">
Image:
<InputText id="image" @bind-Value="voc.Image" />
<ValidationMessage For="@(() => voc.Image)" />
</label>
</p>
<button type="submit">Submit</button> <button type="submit">Submit</button>
</EditForm> </EditForm>

@ -3,6 +3,7 @@ using adminBlazor.Models;
using adminBlazor.Services; using adminBlazor.Services;
using Blazored.LocalStorage; using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@ -33,12 +34,24 @@ namespace adminBlazor.Pages
NavigationManager.NavigateTo("list"); NavigationManager.NavigateTo("list");
} }
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);
voc.Image = memoryStream.ToArray();
}
}
protected async Task OnInitializedAsync() protected async Task OnInitializedAsync()
{ {
var item = await VocListService.GetById(Id); var item = await VocListService.GetById(Id);
voc = VocListFactory.ToModel(item); var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.jpeg");
voc = VocListFactory.ToModel(item,fileContent);
} }
} }
} }

@ -1,5 +1,6 @@
@page "/" @page "/"
@using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Mvc.TagHelpers
@namespace adminBlazor.Pages @namespace adminBlazor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@ -3,12 +3,22 @@
"id": 1, "id": 1,
"name": "Entreprise", "name": "Entreprise",
"image": "link", "image": "link",
"aut": null "aut": null,
"words" : [{
"id": 1,
"firstWord" : "baguette",
"secondWord" : "pain"
}]
}, },
{ {
"id": 2, "id": 2,
"name": "Animaux", "name": "Animaux",
"image": "link", "image": "link",
"aut" : 1 "aut" : 1,
"words": [{
"id": 1,
"firstWord" : "baguette",
"secondWord" : "pain"
}]
} }
] ]
Loading…
Cancel
Save