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