Views fixes
This commit is contained in:
@@ -359,22 +359,15 @@ namespace Business.Business.Sales
|
||||
|
||||
public void RemoveAmount(int productId, double Amount)
|
||||
{
|
||||
if (currentUser.RoleId > 1)
|
||||
var product = Get(productId);
|
||||
if (product != null)
|
||||
{
|
||||
var product = Get(productId);
|
||||
if (product != null)
|
||||
{
|
||||
product.AmountInStock -= Amount;
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Product id not valid!");
|
||||
}
|
||||
product.AmountInStock -= Amount;
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Insufficient Role!");
|
||||
throw new ArgumentException("Product id not valid!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,10 @@ namespace Display.Views
|
||||
public class AdminView : ManagerView
|
||||
{
|
||||
User currentUser;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts a user object.
|
||||
/// <summary>
|
||||
public AdminView(User currentUser) : base(currentUser)
|
||||
{
|
||||
this.currentUser = currentUser;
|
||||
@@ -18,7 +22,7 @@ namespace Display.Views
|
||||
/// Shows the avaliable to the user commands.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The main menu.
|
||||
/// The main menu. Inherited from ManagerView and adds Admin-specific menu.
|
||||
/// </remarks>
|
||||
public override void ShowAvaliableCommands()
|
||||
{
|
||||
@@ -28,6 +32,10 @@ namespace Display.Views
|
||||
/// <summary>
|
||||
/// Asks the user to choose which group of action to use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A choice is given by entering a number from the given list.
|
||||
/// Inherited from ManagerView and expanded with the Admin menu.
|
||||
/// </remarks>
|
||||
public override void ActionHandle()
|
||||
{
|
||||
try
|
||||
@@ -207,8 +215,9 @@ namespace Display.Views
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists all users which match the search term from the database.
|
||||
/// Lists all users who match the search term from the database.
|
||||
/// </summary>
|
||||
public void GetByApproximateName()
|
||||
{
|
||||
@@ -241,7 +250,8 @@ namespace Display.Views
|
||||
string username = Console.ReadLine();
|
||||
Console.Write("Enter password: ");
|
||||
string password = Console.ReadLine();
|
||||
Console.Write("Enter role ID or name (default 1, Cashier): ");
|
||||
Console.WriteLine("Avaliable roles: 1 - Cashier, 2 - Manager, 3 - Admin");
|
||||
Console.Write("Enter role ID or name: ");
|
||||
string role = Console.ReadLine();
|
||||
bool result = int.TryParse(role, out int roleId);
|
||||
if (role == null)
|
||||
@@ -268,27 +278,38 @@ namespace Display.Views
|
||||
/// <summary>
|
||||
/// Changes the role given to a specific user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Asks for a user's ID or name and the new role ID or name.
|
||||
/// </remarks>
|
||||
public void UpdateRole()
|
||||
{
|
||||
try
|
||||
{
|
||||
UserController userctl = new UserController(currentUser);
|
||||
Console.WriteLine("Updating role...");
|
||||
Console.Write("Enter username: ");
|
||||
Console.Write("Enter username or user ID: ");
|
||||
string username = Console.ReadLine();
|
||||
Console.Write("Enter new role ID or name: ");
|
||||
string role = Console.ReadLine();
|
||||
bool result = int.TryParse(role, out int roleId);
|
||||
if (result)
|
||||
bool userResult = int.TryParse(username, out int userId);
|
||||
bool roleResult = int.TryParse(role, out int roleId);
|
||||
if (userResult && roleResult)
|
||||
{
|
||||
userctl.UpdateRole(userId, roleId);
|
||||
}
|
||||
else if (userResult && !roleResult)
|
||||
{
|
||||
userctl.UpdateRole(userId, role);
|
||||
}
|
||||
else if (!userResult && roleResult)
|
||||
{
|
||||
userctl.UpdateRole(username, roleId);
|
||||
Console.WriteLine("Updated role successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
userctl.UpdateRole(username, role);
|
||||
Console.WriteLine("Updated role successfully");
|
||||
}
|
||||
Console.WriteLine("Updated role successfully");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -384,7 +405,7 @@ namespace Display.Views
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Add product to the database.
|
||||
/// Adds a product to the database.
|
||||
/// </summary>
|
||||
public void AddItem()
|
||||
{
|
||||
|
@@ -12,11 +12,28 @@ namespace Display.Views
|
||||
internal ProductController productctrl;
|
||||
private DealController dealctrl;
|
||||
internal User currentUser;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that accepts a user object.
|
||||
/// <summary>
|
||||
/// <remarks>
|
||||
/// User object is used for stock and deal checking.
|
||||
/// Initialises stock and deal controllers.
|
||||
/// </remarks>
|
||||
public BaseView(User currentUser)
|
||||
{
|
||||
this.currentUser = currentUser;
|
||||
this.dealctrl = new DealController(currentUser);
|
||||
this.productctrl = new ProductController(currentUser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows all available commands.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Includes only the basic functions of the program.
|
||||
/// The main menu.
|
||||
/// </remarks>
|
||||
public virtual void ShowAvaliableCommands()
|
||||
{
|
||||
Console.WriteLine();
|
||||
@@ -25,6 +42,14 @@ namespace Display.Views
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("1. Sales");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks the user to choose which group of action to use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A choice is given by entering a number from the given list.
|
||||
/// It's expanded by its inheritors.
|
||||
/// </remarks>
|
||||
public virtual void ActionHandle()
|
||||
{
|
||||
try
|
||||
@@ -51,6 +76,10 @@ namespace Display.Views
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selection menu with base actions.
|
||||
/// </summary>
|
||||
public void SaleHandle()
|
||||
{
|
||||
bool running = true;
|
||||
@@ -90,6 +119,10 @@ namespace Display.Views
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists all products which match the search term from the database.
|
||||
/// </summary>
|
||||
private void SearchItem()
|
||||
{
|
||||
try
|
||||
@@ -97,9 +130,10 @@ namespace Display.Views
|
||||
productctrl = new ProductController(currentUser);
|
||||
Console.Write("Search item: ");
|
||||
string search = Console.ReadLine();
|
||||
Console.WriteLine("Product ID - Name - Price - Amount");
|
||||
foreach (var item in productctrl.GetByApproximateName(search).ToList())
|
||||
{
|
||||
Console.WriteLine($"{item.Id} {item.Name} {item.Price} {item.AmountInStock}");
|
||||
Console.WriteLine($"{item.Id} - {item.Name} - {item.Price} - {item.AmountInStock}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -108,10 +142,15 @@ namespace Display.Views
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sells products. Asks which product and the quantity sold. Prints a summary in the end.
|
||||
/// </summary>
|
||||
private void SaleItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
productctrl = new ProductController(currentUser);
|
||||
List<Product> check = new List<Product>();
|
||||
bool endTyped = false;
|
||||
while (!endTyped)
|
||||
@@ -141,14 +180,16 @@ namespace Display.Views
|
||||
else
|
||||
{
|
||||
endTyped = true;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Check");
|
||||
double sum = 0;
|
||||
check.Reverse();
|
||||
var lastdeals = dealctrl.GetAll().OrderByDescending(x => x.Id).ToArray();
|
||||
for (int i = 0; i < check.Count; i++)
|
||||
for (int i = check.Count - 1; i >= 0; i--)
|
||||
{
|
||||
sum += check[i].Price * lastdeals[i].Amount;
|
||||
int rowNum = i + 1;
|
||||
Console.WriteLine($"{rowNum} {check[i].Name} {check[i].Price}x{lastdeals[i].Amount}");
|
||||
Console.WriteLine($"{rowNum}. {check[i].Name} - {check[i].Price}x{lastdeals[i].Amount}");
|
||||
}
|
||||
Console.WriteLine($"Total: {sum}");
|
||||
}
|
||||
@@ -156,7 +197,6 @@ namespace Display.Views
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,8 @@ namespace Display.Views
|
||||
/// <summary>
|
||||
/// <remarks>
|
||||
/// User object is used for stock and deal checking.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Initialises stock and deal controllers.
|
||||
/// </remarks>
|
||||
|
||||
public ManagerView(User currentUser):base(currentUser)
|
||||
{
|
||||
stockctrl = new StockController(currentUser);
|
||||
@@ -32,12 +29,8 @@ namespace Display.Views
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Inherits all available commands from the base view.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// The main menu.
|
||||
/// </remarks>
|
||||
|
||||
|
||||
public override void ShowAvaliableCommands()
|
||||
{
|
||||
base.ShowAvaliableCommands();
|
||||
@@ -48,15 +41,10 @@ namespace Display.Views
|
||||
/// Asks the user to choose which group of action to use.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If user inputs the digit 1, returns selling handles.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// If user inputs the digit 2, returns managing handles.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// If user inputs the digit 1, returns selling handles.
|
||||
/// If user inputs the digit 2, returns managing handles.
|
||||
/// If user inputs something else, the operation is invalid.
|
||||
/// </remarks>
|
||||
|
||||
public override void ActionHandle()
|
||||
{
|
||||
try
|
||||
@@ -93,7 +81,6 @@ namespace Display.Views
|
||||
/// <remarks>
|
||||
/// Requires role level 2 (Manager).
|
||||
/// </remarks>
|
||||
|
||||
public void ManageHandle()
|
||||
{
|
||||
bool running = true;
|
||||
@@ -104,11 +91,12 @@ namespace Display.Views
|
||||
Console.WriteLine("0. Back");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stock Managment");
|
||||
Console.WriteLine("1. GetAll");
|
||||
Console.WriteLine("2. Get");
|
||||
Console.WriteLine("3. GetByTime");
|
||||
Console.WriteLine("4. Add");
|
||||
Console.WriteLine("1. List all stocks");
|
||||
Console.WriteLine("2. Get stock by ID");
|
||||
Console.WriteLine("3. List stocks by time");
|
||||
Console.WriteLine("4. Add stock");
|
||||
Console.WriteLine("5. Delete");
|
||||
Console.WriteLine("6. List deals by user");
|
||||
Console.Write("> ");
|
||||
try
|
||||
{
|
||||
@@ -130,6 +118,9 @@ namespace Display.Views
|
||||
case 5:
|
||||
Delete();
|
||||
break;
|
||||
case 6:
|
||||
GetByUser();
|
||||
break;
|
||||
case 0:
|
||||
running = false;
|
||||
break;
|
||||
@@ -149,7 +140,6 @@ namespace Display.Views
|
||||
/// <summary>
|
||||
/// Lists all information about stock from the database.
|
||||
/// </summary>
|
||||
|
||||
public void GetAll()
|
||||
{
|
||||
try
|
||||
@@ -171,8 +161,7 @@ namespace Display.Views
|
||||
|
||||
/// <summary>
|
||||
/// Lists all registered information about stocks from the database.
|
||||
/// </summary>
|
||||
|
||||
/// </summary>
|
||||
public void Get()
|
||||
{
|
||||
|
||||
@@ -197,8 +186,6 @@ namespace Display.Views
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Inputs start time and end time.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Lists all information about stocks from the database in real time.
|
||||
/// </remarks>
|
||||
public void GetByTime()
|
||||
@@ -228,14 +215,9 @@ namespace Display.Views
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Entering product name and amount.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// If the result is true, returns a stock with product id, amount and a real time.
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// Else returns a stock with product name, amount and a real time.
|
||||
/// </remarks>
|
||||
|
||||
public void Add()
|
||||
{
|
||||
try
|
||||
@@ -265,7 +247,6 @@ namespace Display.Views
|
||||
/// <summary>
|
||||
/// Deletes a stock from the database.
|
||||
/// </summary>
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
try
|
||||
@@ -282,5 +263,41 @@ namespace Display.Views
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets deals by the user who made them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Inputs username or user ID.
|
||||
/// Lists all deals made by a user from the database.
|
||||
/// </remarks>
|
||||
public void GetByUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Getting stock by time...");
|
||||
Console.Write("Enter username or user ID: ");
|
||||
string input = Console.ReadLine();
|
||||
int.TryParse(input, out int inputId);
|
||||
ICollection<Deal> output;
|
||||
if (inputId != 0)
|
||||
{
|
||||
output = dealctrl.GetByUser(inputId);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = dealctrl.GetByUser(input);
|
||||
}
|
||||
Console.WriteLine("Deal ID - Product ID - Amount - Time");
|
||||
foreach (var item in output)
|
||||
{
|
||||
Console.WriteLine($"{item.Id} - {item.ProductId} - {item.Amount} - {item.Time}");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user