mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-12 22:11:54 +00:00
68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class InventoryContext : DbContext
|
|
{
|
|
public int Id {get; set;}
|
|
public string Name { get; set; }
|
|
public string Brand { get; set; }
|
|
public string? SerialNumber { get; set; }
|
|
public string? Status { get; set; }
|
|
public float? RentalPrice { get; set; }
|
|
public float? ReplacementCost { get; set; }
|
|
public string? Notes { get; set; }
|
|
|
|
public string DbPath { get; }
|
|
|
|
public InventoryContext()
|
|
{
|
|
var folder = Environment.SpecialFolder.LocalApplicationData;
|
|
var path = Environment.GetFolderPath(folder);
|
|
DbPath = System.IO.Path.Join(path, "blogging.db");
|
|
}
|
|
|
|
// The following configures EF to create a Sqlite database file in the
|
|
// special "local" folder for your platform.
|
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
|
=> 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();
|
|
}
|
|
} |