mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
things pt2
This commit is contained in:
@@ -3,6 +3,7 @@ using BarkMan.DB;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<InventoryContext>();
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class InventoryContext : DbContext
|
|||||||
{
|
{
|
||||||
var folder = Environment.SpecialFolder.LocalApplicationData;
|
var folder = Environment.SpecialFolder.LocalApplicationData;
|
||||||
var path = Environment.GetFolderPath(folder);
|
var path = Environment.GetFolderPath(folder);
|
||||||
DbPath = System.IO.Path.Join(path, "blogging.db");
|
DbPath = System.IO.Path.Join(path, "inventory.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following configures EF to create a Sqlite database file in the
|
// The following configures EF to create a Sqlite database file in the
|
||||||
@@ -27,42 +27,4 @@ public class InventoryContext : DbContext
|
|||||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
=> options.UseSqlite($"Data Source={DbPath}");
|
=> options.UseSqlite($"Data Source={DbPath}");
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InventoryDb
|
|
||||||
{
|
|
||||||
|
|
||||||
public static List<InventoryItem> GetInventory()
|
|
||||||
{
|
|
||||||
return _inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InventoryItem ? GetInventory(int id)
|
|
||||||
{
|
|
||||||
return _inventory.SingleOrDefault(item => item.Id == id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InventoryItem CreateInventoryItem(InventoryItem item)
|
|
||||||
{
|
|
||||||
_inventory.Add(item);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InventoryItem UpdateItem(InventoryItem update)
|
|
||||||
{
|
|
||||||
_inventory = _inventory.Select(item =>
|
|
||||||
{
|
|
||||||
if (item.Id == update.Id)
|
|
||||||
{
|
|
||||||
item.Name = update.Name;
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}).ToList();
|
|
||||||
return update;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveItem(int id)
|
|
||||||
{
|
|
||||||
_inventory = _inventory.FindAll(item => item.Id != id).ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user