|
|
@ -36,6 +36,22 @@ namespace myBlazorApp.Services
|
|
|
|
/// Add the item to the current data
|
|
|
|
/// Add the item to the current data
|
|
|
|
currentData.Add(ItemFactory.Create(model));
|
|
|
|
currentData.Add(ItemFactory.Create(model));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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}/{model.Name}.png");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write the file content
|
|
|
|
|
|
|
|
await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
// Save the data
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,6 +107,32 @@ namespace myBlazorApp.Services
|
|
|
|
throw new Exception($"Unable to found the item with ID: {id}");
|
|
|
|
throw new Exception($"Unable to found the item with ID: {id}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the image
|
|
|
|
|
|
|
|
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the folder "images" exist
|
|
|
|
|
|
|
|
if (!imagePathInfo.Exists)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
imagePathInfo.Create();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete the previous image
|
|
|
|
|
|
|
|
if (item.Name != model.Name)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var oldFileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (oldFileName.Exists)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
File.Delete(oldFileName.FullName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Determine the image name
|
|
|
|
|
|
|
|
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write the file content
|
|
|
|
|
|
|
|
await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
|
|
|
|
|
|
|
|
|
|
|
|
// Modify the content of the item
|
|
|
|
// Modify the content of the item
|
|
|
|
ItemFactory.Update(item, model);
|
|
|
|
ItemFactory.Update(item, model);
|
|
|
|
|
|
|
|
|
|
|
@ -109,6 +151,14 @@ namespace myBlazorApp.Services
|
|
|
|
// Delete item in
|
|
|
|
// Delete item in
|
|
|
|
currentData.Remove(item);
|
|
|
|
currentData.Remove(item);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete the image
|
|
|
|
|
|
|
|
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
|
|
|
|
|
|
|
|
var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fileName.Exists)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
File.Delete(fileName.FullName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
// Save the data
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|