diff --git a/TheMiddleman/BusinessLogic/MiddlemanService.cs b/TheMiddleman/BusinessLogic/MiddlemanService.cs index 112ca46..15f859a 100644 --- a/TheMiddleman/BusinessLogic/MiddlemanService.cs +++ b/TheMiddleman/BusinessLogic/MiddlemanService.cs @@ -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) @@ -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; } diff --git a/TheMiddleman/DataAccess/IMiddlemanRespository.cs b/TheMiddleman/DataAccess/IMiddlemanRepository.cs similarity index 88% rename from TheMiddleman/DataAccess/IMiddlemanRespository.cs rename to TheMiddleman/DataAccess/IMiddlemanRepository.cs index 1794f01..3f93983 100644 --- a/TheMiddleman/DataAccess/IMiddlemanRespository.cs +++ b/TheMiddleman/DataAccess/IMiddlemanRepository.cs @@ -2,7 +2,7 @@ namespace TheMiddleman.DataAccess { - public interface IMiddlemanRespository + public interface IMiddlemanRepository { List RetrieveAllMiddlemen(); List RetrieveBankruptMiddlemen(); diff --git a/TheMiddleman/DataAccess/MiddlemanRespository.cs b/TheMiddleman/DataAccess/MiddlemanRepository.cs similarity index 92% rename from TheMiddleman/DataAccess/MiddlemanRespository.cs rename to TheMiddleman/DataAccess/MiddlemanRepository.cs index f72ff70..8083a31 100644 --- a/TheMiddleman/DataAccess/MiddlemanRespository.cs +++ b/TheMiddleman/DataAccess/MiddlemanRepository.cs @@ -2,7 +2,7 @@ namespace TheMiddleman.DataAccess { - public class MiddlemanRespository : IMiddlemanRespository + public class MiddlemanRepository : IMiddlemanRepository { private List _middlemen = new List(); private List _bankruptMiddlemen = new List(); diff --git a/TheMiddleman/UserInterface/ConsoleUI.cs b/TheMiddleman/UserInterface/ConsoleUI.cs index c42aae4..3d2ba8d 100644 --- a/TheMiddleman/UserInterface/ConsoleUI.cs +++ b/TheMiddleman/UserInterface/ConsoleUI.cs @@ -255,7 +255,20 @@ 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() @@ -263,12 +276,6 @@ 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 products = _marketService.ProductService().GetAllProducts();