ef core
This commit is contained in:
89
MySolution/InventoryManagement/Program.cs
Normal file
89
MySolution/InventoryManagement/Program.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
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)");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user