Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Dec 1, 2023
1 parent 29da280 commit ca2820a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
14 changes: 4 additions & 10 deletions TheMiddleman/BusinessLogic/MiddlemanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Purchase(Middleman middleman, Product selectedProduct, int quantity,
}
}

public void Sale(Middleman middleman, Product product, int quantity)
public void SellProduct(Middleman middleman, Product product, int quantity)
{
middleman.Warehouse[product] -= quantity;
if (middleman.Warehouse[product] == 0)
Expand All @@ -54,20 +54,14 @@ public void Sale(Middleman middleman, Product product, int quantity)
middleman.AccountBalance += quantity * product.SellingPrice;
}

public void IncreaseWarehouseCapacity(Middleman middleman)
public void IncreaseWarehouseCapacity(Middleman middleman, int increaseAmount)
{
int increaseAmount;
if (!int.TryParse(ConsoleUI.GetUserInput(), out increaseAmount) || increaseAmount <= 0)
{
ConsoleUI.ShowErrorLog("Vergrößerung des Lagers abgebrochen.");
return;
}
int costForIncrease = increaseAmount * 50;
if (middleman.AccountBalance < costForIncrease)
{
ConsoleUI.ShowErrorLog($"Nicht genug Geld für die Vergrößerung des Lagers vorhanden.\nVerfügbares Guthaben: ${middleman.AccountBalance}");
return;
throw new InsufficientFundsException($"Not enough funds for warehouse expansion. Available funds: ${middleman.AccountBalance}");
}

middleman.AccountBalance -= costForIncrease;
middleman.MaxStorageCapacity += increaseAmount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TheMiddleman.DataAccess
{
public interface IMiddlemanRespository
public interface IMiddlemanRepository
{
List<Middleman> RetrieveAllMiddlemen();
List<Middleman> RetrieveBankruptMiddlemen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TheMiddleman.DataAccess
{
public class MiddlemanRespository : IMiddlemanRespository
public class MiddlemanRepository : IMiddlemanRepository
{
private List<Middleman> _middlemen = new List<Middleman>();
private List<Middleman> _bankruptMiddlemen = new List<Middleman>();
Expand Down
21 changes: 14 additions & 7 deletions TheMiddleman/UserInterface/ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,27 @@ private void ShowSelling(Middleman middleman)

private void ShowWarehouseExpansion(Middleman middleman)
{
ShowExtendingWarehouse(middleman);
try
{
ShowMessage("How many units do you want to expand the warehouse by? ($50 per unit)");
int increaseAmount = int.Parse(GetUserInput());
_marketService.MiddlemanService().IncreaseWarehouseCapacity(middleman, increaseAmount);
}
catch (InsufficientFundsException ex)
{
ShowErrorLog(ex.Message);
}
catch (FormatException)
{
ShowErrorLog("Invalid input. Please enter a positive number.");
}
}

private void NotifyInvalidMenuChoice()
{
ShowErrorLog("Ungültige Auswahl. Bitte erneut versuchen.");
}

private void ShowExtendingWarehouse(Middleman middleman)
{
ShowMessage("Um wie viel Einheiten möchten Sie das Lager vergrößern? ($50 pro Einheit)");
_marketService.MiddlemanService().IncreaseWarehouseCapacity(middleman);
}

private void ShowAllProducts()
{
List<Product> products = _marketService.ProductService().GetAllProducts();
Expand Down

0 comments on commit ca2820a

Please sign in to comment.