You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
4.3 KiB
101 lines
4.3 KiB
using InventoryManagement.Components;
|
|
|
|
namespace InventoryManagement
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
using (var context = new InventoryContext())
|
|
{
|
|
context.Database.EnsureCreated();
|
|
}
|
|
|
|
var InventoryManager = new InventoryManager();
|
|
while (true)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("Pease Enter the command.");
|
|
Console.WriteLine("(show: Show current Inventory, add: Add new product, buy: Buy product, sell: Sell product, acc: Add accessary)");
|
|
Console.Write("CMD> ");
|
|
string cmd = Console.ReadLine().ToLower();
|
|
switch (cmd)
|
|
{
|
|
case "show":
|
|
InventoryManager.ShowInventory();
|
|
break;
|
|
case "add":
|
|
{
|
|
Console.Write("\tName: ");
|
|
string name = Console.ReadLine();
|
|
Console.Write("\tDefault quantity: ");
|
|
string qt = Console.ReadLine();
|
|
int quantity = 0;
|
|
if (!int.TryParse(qt, out quantity))
|
|
{
|
|
Console.WriteLine("Invalid quanitity.");
|
|
break;
|
|
}
|
|
Product product = new Product() { Name = name, Quantity = quantity };
|
|
InventoryManager.AddProduct(product);
|
|
break;
|
|
}
|
|
|
|
case "buy":
|
|
{
|
|
Console.Write("\tId or Name: ");
|
|
string name = Console.ReadLine();
|
|
int id = 0;
|
|
bool idAvailable = int.TryParse(name, out id);
|
|
Console.Write("\tQuantity: ");
|
|
string qt = Console.ReadLine();
|
|
int quantity = 0;
|
|
if (!int.TryParse(qt, out quantity))
|
|
{
|
|
Console.WriteLine("Invalid quanitity.");
|
|
break;
|
|
}
|
|
if (idAvailable)
|
|
InventoryManager.BuyProduct(id, quantity);
|
|
else
|
|
InventoryManager.BuyProduct(name, quantity);
|
|
break;
|
|
}
|
|
case "sell":
|
|
{
|
|
Console.Write("\tId or Name: ");
|
|
string name = Console.ReadLine();
|
|
int id = 0;
|
|
bool idAvailable = int.TryParse(name, out id);
|
|
Console.Write("\tQuantity: ");
|
|
string qt = Console.ReadLine();
|
|
int quantity = 0;
|
|
if (!int.TryParse(qt, out quantity))
|
|
{
|
|
Console.WriteLine("Invalid quanitity.");
|
|
break;
|
|
}
|
|
if (idAvailable)
|
|
InventoryManager.SellProduct(id, quantity);
|
|
else
|
|
InventoryManager.SellProduct(name, quantity);
|
|
break;
|
|
}
|
|
case "acc":
|
|
{
|
|
Console.Write("\tProduct id: ");
|
|
string productId = Console.ReadLine();
|
|
int pId = int.Parse(productId);
|
|
Console.Write("\tAccessary name: ");
|
|
string name = Console.ReadLine();
|
|
Console.Write("\tAccessary description: ");
|
|
string desc = Console.ReadLine();
|
|
InventoryManager.AddAccessary(pId, name, desc);
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
} |