|
|
@ -48,23 +48,9 @@ namespace Blazor.Services
|
|
|
|
CreatedDate = DateTime.Now
|
|
|
|
CreatedDate = DateTime.Now
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> Count()
|
|
|
|
public async Task<int> Count()
|
|
|
@ -120,31 +106,6 @@ namespace Blazor.Services
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Save the image
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemFactory.Update(item, model);
|
|
|
|
ItemFactory.Update(item, model);
|
|
|
|
|
|
|
|
|
|
|
|
// Modify the content of the item
|
|
|
|
// Modify the content of the item
|
|
|
@ -170,15 +131,6 @@ namespace Blazor.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -200,5 +152,6 @@ namespace Blazor.Services
|
|
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(items);
|
|
|
|
return Task.FromResult(items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|