Views, Add Time in Deal & Stock
This commit is contained in:
@@ -17,32 +17,35 @@ namespace Display.Views
|
||||
public override void ShowAvaliableCommands()
|
||||
{
|
||||
base.ShowAvaliableCommands();
|
||||
Console.WriteLine("4. User Managment");
|
||||
Console.WriteLine("3. Administration");
|
||||
}
|
||||
public override void ActionHandle()
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
while (true)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else if (input == 1)
|
||||
{
|
||||
SaleHandle();
|
||||
}
|
||||
else if (input == 2)
|
||||
{
|
||||
ManageHandle();
|
||||
}
|
||||
else if (input == 3)
|
||||
{
|
||||
AdminHandle();
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
else if (input == 1)
|
||||
{
|
||||
SaleHandle();
|
||||
}
|
||||
else if (input == 2)
|
||||
{
|
||||
ManageHandle();
|
||||
}
|
||||
else if (input == 3)
|
||||
{
|
||||
AdminHandle();
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -54,16 +57,22 @@ namespace Display.Views
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("User Managment");
|
||||
Console.WriteLine("1. GetAll");
|
||||
Console.WriteLine("2. Get");
|
||||
Console.WriteLine("3. GetByApproximateName");
|
||||
Console.WriteLine("4. RegisterItem");
|
||||
Console.WriteLine("5. UpdateRole");
|
||||
Console.WriteLine("6. UpdateName");
|
||||
Console.WriteLine("4. Register user");
|
||||
Console.WriteLine("5. Update Role");
|
||||
Console.WriteLine("6. Update username");
|
||||
Console.WriteLine("7. UpdatePassword");
|
||||
Console.WriteLine("8. Delete");
|
||||
Console.WriteLine("9. Exit");
|
||||
Console.Write("Your choice: ");
|
||||
Console.WriteLine("8. Delete User");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Product Managment");
|
||||
Console.WriteLine("9. AddItem");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("10. Back");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int choice = int.Parse(Console.ReadLine());
|
||||
@@ -94,6 +103,9 @@ namespace Display.Views
|
||||
Delete();
|
||||
break;
|
||||
case 9:
|
||||
AddItem();
|
||||
break;
|
||||
case 10:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
@@ -286,5 +298,21 @@ namespace Display.Views
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
public void AddItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Adding item to database...");
|
||||
Console.Write("Enter product name: ");
|
||||
string product = Console.ReadLine();
|
||||
Console.Write("Enter price: ");
|
||||
double price = double.Parse(Console.ReadLine());
|
||||
productctrl.AddItem(product, price);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ namespace Display.Views
|
||||
{
|
||||
public class BaseView
|
||||
{
|
||||
ProductController productctrl;
|
||||
internal ProductController productctrl;
|
||||
DealController dealctrl;
|
||||
public BaseView(User currentUser)
|
||||
{
|
||||
@@ -18,25 +18,30 @@ namespace Display.Views
|
||||
}
|
||||
public virtual void ShowAvaliableCommands()
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("=== MAIN MENU ===");
|
||||
Console.WriteLine("0. Exit");
|
||||
Console.WriteLine("1. Sales");
|
||||
}
|
||||
public virtual void ActionHandle()
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
while (true)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else if (input == 1)
|
||||
{
|
||||
SaleHandle();
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
else if (input == 1)
|
||||
{
|
||||
SaleHandle();
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -48,10 +53,12 @@ namespace Display.Views
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Deal Managment");
|
||||
Console.WriteLine("1. Search");
|
||||
Console.WriteLine("2. Sale");
|
||||
Console.WriteLine("3. Exit");
|
||||
Console.Write("Your choice: ");
|
||||
Console.WriteLine("3. Back");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int choice = int.Parse(Console.ReadLine());
|
||||
@@ -83,12 +90,12 @@ namespace Display.Views
|
||||
try
|
||||
{
|
||||
Console.Write("Search item: ");
|
||||
string search = Console.ReadLine();
|
||||
ICollection<Product> productsFound = productctrl.GetByApproximateName(search).ToArray();
|
||||
foreach (var item in productsFound)
|
||||
{
|
||||
Console.WriteLine($"{item.Id} {item.Name} {item.Price} {item.AmountInStock}");
|
||||
}
|
||||
string search = Console.ReadLine();
|
||||
ICollection<Product> productsFound = productctrl.GetByApproximateName(search).ToArray();
|
||||
foreach (var item in productsFound)
|
||||
{
|
||||
Console.WriteLine($"{item.Id} {item.Name} {item.Price} {item.AmountInStock}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -103,19 +110,19 @@ namespace Display.Views
|
||||
Console.Write("Type in item id or name: ");
|
||||
string itemInput = Console.ReadLine();
|
||||
int itemId;
|
||||
if (Int32.TryParse(itemInput, out itemId))
|
||||
if (int.TryParse(itemInput, out itemId))
|
||||
{
|
||||
var productToAdd = productctrl.Get(itemId);
|
||||
Console.Write("Amount: ");
|
||||
double amount = double.Parse(Console.ReadLine());
|
||||
dealctrl.Add(itemId, amount);
|
||||
dealctrl.Add(itemId, amount, DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
var productToAdd = productctrl.Get(itemInput);
|
||||
Console.Write("Amount: ");
|
||||
double amount = double.Parse(Console.ReadLine());
|
||||
dealctrl.Add(itemInput, amount);
|
||||
dealctrl.Add(itemInput, amount, DateTime.Now);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -22,24 +22,27 @@ namespace Display.Views
|
||||
}
|
||||
public override void ActionHandle()
|
||||
{
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int input = int.Parse(Console.ReadLine());
|
||||
if (input == 0)
|
||||
while (true)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
ShowAvaliableCommands();
|
||||
Console.Write("> ");
|
||||
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");
|
||||
}
|
||||
else if (input == 1)
|
||||
{
|
||||
SaleHandle();
|
||||
}
|
||||
else if (input == 2)
|
||||
{
|
||||
ManageHandle();
|
||||
}
|
||||
else Console.WriteLine("Invalid operation");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -51,13 +54,15 @@ namespace Display.Views
|
||||
bool running = true;
|
||||
while (running)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stock Managment");
|
||||
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: ");
|
||||
Console.WriteLine("6. Back");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
int choice = int.Parse(Console.ReadLine());
|
||||
@@ -97,11 +102,11 @@ namespace Display.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Getting all stock...");
|
||||
|
||||
Console.WriteLine("Getting all stock...");
|
||||
Console.WriteLine("ID - Product ID - Amount - Time");
|
||||
foreach (var item in stockctrl.GetAll())
|
||||
{
|
||||
Console.WriteLine($"{item.Id} {item.ProductId} {item.Amount} ");
|
||||
Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -119,7 +124,9 @@ namespace Display.Views
|
||||
{
|
||||
Console.Write("Enter stock id: ");
|
||||
int id = int.Parse(Console.ReadLine());
|
||||
stockctrl.Get(id);
|
||||
var result = stockctrl.Get(id);
|
||||
Console.WriteLine("ID - Product ID - Amount - Time");
|
||||
Console.WriteLine($"{result.Id} - {result.ProductId} - {result.Amount} - {result.Time}");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -135,11 +142,16 @@ namespace Display.Views
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Getting stock by time...");
|
||||
Console.WriteLine("Enter start time: ");
|
||||
Console.Write("Enter start time: ");
|
||||
DateTime startTime = DateTime.Parse(Console.ReadLine());
|
||||
Console.WriteLine("Enter end time: ");
|
||||
Console.Write("Enter end time: ");
|
||||
DateTime endTime = DateTime.Parse(Console.ReadLine());
|
||||
stockctrl.GetByTime(startTime, endTime);
|
||||
Console.WriteLine("ID - Product ID - Amount - Time");
|
||||
foreach (var item in stockctrl.GetByTime(startTime, endTime))
|
||||
{
|
||||
Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -151,19 +163,19 @@ namespace Display.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Adding stock by product id...");
|
||||
Console.WriteLine("Adding stock by product id or name...");
|
||||
Console.Write("Enter product ID or name: ");
|
||||
string product = Console.ReadLine();
|
||||
Console.Write("Enter stock amount:");
|
||||
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);
|
||||
stockctrl.Add(productId, amount, DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
stockctrl.Add(product, amount);
|
||||
stockctrl.Add(product, amount, DateTime.Now);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -178,9 +190,9 @@ namespace Display.Views
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Deleting stock...");
|
||||
Console.Write("Enter deal id: ");
|
||||
Console.Write("Enter stock id: ");
|
||||
int id = int.Parse(Console.ReadLine());
|
||||
dealctrl.Delete(id);
|
||||
stockctrl.Delete(id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user