|
|
|
@ -201,123 +201,62 @@ namespace ValblazeProject.Services
|
|
|
|
|
return (await _localStorage.GetItemAsync<Item[]>("data")).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************ Inventory ************************
|
|
|
|
|
public async Task supprInventory()
|
|
|
|
|
/************************ Inventory ************************/
|
|
|
|
|
public async Task SupprInventory(Inventory itemSearch)
|
|
|
|
|
{
|
|
|
|
|
// Get the current data
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<Inventory>("data");
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
|
|
|
|
|
|
|
|
|
|
// Get the item int the list
|
|
|
|
|
var item = currentData.FirstOrDefault(w => w.Id == id);
|
|
|
|
|
var item = currentData.FirstOrDefault(w => w.position == itemSearch.position);
|
|
|
|
|
|
|
|
|
|
// Delete item in
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Inventory> getInventory()
|
|
|
|
|
public async Task<List<Inventory>> GetInventory()
|
|
|
|
|
{
|
|
|
|
|
// Get the current data
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<Inventory>("data");
|
|
|
|
|
|
|
|
|
|
// Get the item int the list
|
|
|
|
|
var item = currentData.FirstOrDefault(w => w.Id == id);
|
|
|
|
|
|
|
|
|
|
// Check if item exist
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Unable to found the item with ID: {id}");
|
|
|
|
|
}
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
return currentData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task putInventory()
|
|
|
|
|
public async Task PutInventory(Inventory invent)
|
|
|
|
|
{
|
|
|
|
|
// Get the current data
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<Item>>("data");
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
|
|
|
|
|
|
|
|
|
|
// Get the item int the list
|
|
|
|
|
var item = currentData.FirstOrDefault(w => w.Id == id);
|
|
|
|
|
var item = currentData.FirstOrDefault(w => w.position == invent.position);
|
|
|
|
|
|
|
|
|
|
// Check if item exist
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
throw new Exception($"Unable to found the item with ID: {item.position}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
ItemFactory.Update(item, model);
|
|
|
|
|
item.position = invent.position;
|
|
|
|
|
item.numberItem = invent.numberItem;
|
|
|
|
|
item.itemName = invent.itemName;
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
|
await _localStorage.SetItemAsync("KeyInvent", currentData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task postInventory()
|
|
|
|
|
public async Task PostInventory(Inventory invent)
|
|
|
|
|
{
|
|
|
|
|
// Get the current data
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<Item>>("data");
|
|
|
|
|
|
|
|
|
|
// Simulate the Id
|
|
|
|
|
model.Id = currentData.Max(s => s.Id) + 1;
|
|
|
|
|
var currentData = await _localStorage.GetItemAsync<List<Inventory>>("KeyInvent");
|
|
|
|
|
|
|
|
|
|
// Add the item to the current data
|
|
|
|
|
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);
|
|
|
|
|
currentData.Add(invent);
|
|
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
|
await _localStorage.SetItemAsync("data", currentData);
|
|
|
|
|
}*/
|
|
|
|
|
await _localStorage.SetItemAsync("KeyInvent", currentData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|