|
|
|
@ -41,19 +41,7 @@ namespace adminBlazor.Services
|
|
|
|
|
currentData.Add(UserFactory.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
|
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
@ -69,7 +57,6 @@ namespace adminBlazor.Services
|
|
|
|
|
public async Task<User> GetById(int id)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//var currentData = await LocalStorage.GetItemAsync<User[]>("user.json");
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<User>>("data");
|
|
|
|
|
|
|
|
|
|
var user = currentData.FirstOrDefault(w => w.Id == id);
|
|
|
|
@ -90,7 +77,7 @@ namespace adminBlazor.Services
|
|
|
|
|
public async Task Update(int id, UserModel model)
|
|
|
|
|
{
|
|
|
|
|
// Get the current data
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<User[]>("data");
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<User>>("data");
|
|
|
|
|
|
|
|
|
|
var user = currentData.FirstOrDefault(w => w.Id == id);
|
|
|
|
|
|
|
|
|
@ -101,30 +88,7 @@ namespace adminBlazor.Services
|
|
|
|
|
|
|
|
|
|
// 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 (user.Name != model.Name)
|
|
|
|
|
{
|
|
|
|
|
// var oldFileName = new FileInfo($"{imagePathInfo}/{user.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.Image);
|
|
|
|
|
|
|
|
|
|
UserFactory.Update(user, model);
|
|
|
|
|
|
|
|
|
|
// Modify the content of the item
|
|
|
|
@ -146,13 +110,7 @@ namespace adminBlazor.Services
|
|
|
|
|
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
|
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
|