Presentaion, Views, CLI

This commit is contained in:
Dimitar Byalkov
2021-03-19 16:58:06 +02:00
parent cb1206661f
commit 17fbd10d03
8 changed files with 229 additions and 105 deletions

View File

@@ -20,6 +20,79 @@ namespace Display.Views
base.ShowAvaliableCommands();
Console.WriteLine("2. Stock");
}
public override void ActionHandle()
{
ShowAvaliableCommands();
Console.Write("> ");
try
{
int input = int.Parse(Console.ReadLine());
if (input == 0)
{
Environment.Exit(0);
}
else if (input == 1)
{
SaleHandle();
}
else if (input == 2)
{
ManageHandle();
}
else Console.WriteLine("Invalid operation");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public void ManageHandle()
{
bool running = true;
while (running)
{
Console.WriteLine("1. GetAll");
Console.WriteLine("2. Get");
Console.WriteLine("3. GetByTime");
Console.WriteLine("4. Add");
Console.WriteLine("5. Delete");
Console.WriteLine("6. Exit");
Console.Write("Your choice: ");
try
{
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
GetAll();
break;
case 2:
Get();
break;
case 3:
GetByTime();
break;
case 4:
Add();
break;
case 5:
Delete();
break;
case 6:
running = false;
break;
default:
Console.WriteLine("Invalid Option!");
break;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
public void GetAll()
{
try
@@ -39,13 +112,13 @@ namespace Display.Views
}
public void Get(int id)
public void Get()
{
try
{
Console.WriteLine("Enter stock id...");
id = int.Parse(Console.ReadLine());
Console.Write("Enter stock id: ");
int id = int.Parse(Console.ReadLine());
stockctrl.Get(id);
}
@@ -74,16 +147,24 @@ namespace Display.Views
}
}
public void Add(int productId, double amount)
public void Add()
{
try
{
Console.WriteLine("Adding stock by product id...");
Console.WriteLine("Enter product id: ");
productId = int.Parse(Console.ReadLine());
Console.WriteLine("Enter stock amount:");
amount = double.Parse(Console.ReadLine());
stockctrl.Add(productId, amount);
Console.Write("Enter product ID or name: ");
string product = Console.ReadLine();
Console.Write("Enter stock amount:");
double amount = double.Parse(Console.ReadLine());
bool result = int.TryParse(product, out int productId);
if (result)
{
stockctrl.Add(productId, amount);
}
else
{
stockctrl.Add(product, amount);
}
}
catch (Exception e)
{
@@ -92,30 +173,13 @@ namespace Display.Views
}
}
public void Add(string productName, double amount)
public void Delete()
{
try
{
Console.WriteLine("Adding stock by product name...");
Console.WriteLine("Enter product name: ");
productName = Console.ReadLine();
amount = double.Parse(Console.ReadLine());
stockctrl.Add(productName, amount);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public void Delete(int id)
{
try
{
Console.WriteLine("Deleting stock");
Console.WriteLine("Enter deal id: ");
id = int.Parse(Console.ReadLine());
Console.WriteLine("Deleting stock...");
Console.Write("Enter deal id: ");
int id = int.Parse(Console.ReadLine());
dealctrl.Delete(id);
}
catch (Exception e)