Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. namespace SoftUniRestaurant.Core
  2. {
  3. using SoftUniRestaurant.Factories;
  4. using SoftUniRestaurant.Models.Drinks.Contracts;
  5. using SoftUniRestaurant.Models.Foods.Contracts;
  6. using SoftUniRestaurant.Models.Tables.Contracts;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11.  
  12. public class RestaurantController
  13. {
  14. private List<IFood> menu;
  15. private List<IDrink> drinks;
  16. private List<ITable> tables;
  17. private FoodFactory foodFactory;
  18. private DrinkFactory drinkFactory;
  19. private TableFactory tableFactory;
  20. private decimal income;
  21.  
  22. public RestaurantController()
  23. {
  24. this.menu = new List<IFood>();
  25. this.drinks = new List<IDrink>();
  26. this.tables = new List<ITable>();
  27. this.foodFactory = new FoodFactory();
  28. this.drinkFactory = new DrinkFactory();
  29. this.tableFactory = new TableFactory();
  30. this.income = 0;
  31.  
  32. }
  33.  
  34. public string AddFood(string type, string name, decimal price)
  35. {
  36. var food = foodFactory.CreateFood(type, name, price);
  37.  
  38. menu.Add(food);
  39.  
  40. return $"Added {name} ({type}) with price {price:f2} to the pool";
  41. }
  42.  
  43. public string AddDrink(string type, string name, int servingSize, string brand)
  44. {
  45. var drink = drinkFactory.CreateDrink(type, name, servingSize, brand);
  46.  
  47. drinks.Add(drink);
  48.  
  49. return $"Added {name} ({brand}) to the drink pool";
  50. }
  51.  
  52. public string AddTable(string type, int tableNumber, int capacity)
  53. {
  54. var table = tableFactory.CreateTable(type, tableNumber, capacity);
  55.  
  56. tables.Add(table);
  57.  
  58. return $"Added table number {tableNumber} in the restaurant";
  59. }
  60.  
  61. public string ReserveTable(int numberOfPeople)
  62. {
  63. ITable freeTable = tables.FirstOrDefault(t => t.IsReserved == false && t.NumberOfPeople >= numberOfPeople);
  64.  
  65. if (freeTable == null)
  66. {
  67. return $"No available table for {numberOfPeople} people";
  68. }
  69.  
  70. freeTable.Reserve(numberOfPeople);
  71.  
  72. return $"Table {freeTable.TableNumber} has been reserved for {numberOfPeople} people";
  73. }
  74.  
  75. public string OrderFood(int tableNumber, string foodName)
  76. {
  77. var table = tables.FirstOrDefault(t => t.TableNumber == tableNumber);
  78.  
  79. if (table == null)
  80. {
  81. return $"Could not find table with {tableNumber}";
  82. }
  83.  
  84. var food = menu.FirstOrDefault(f => f.Name == foodName);
  85.  
  86. if (food == null)
  87. {
  88. return $"No {foodName} in the menu";
  89. }
  90.  
  91. return $"Table {tableNumber} ordered {foodName}";
  92. }
  93.  
  94. public string OrderDrink(int tableNumber, string drinkName, string drinkBrand)
  95. {
  96. var table = tables.FirstOrDefault(t => t.TableNumber == tableNumber);
  97.  
  98. if (table == null)
  99. {
  100. return $"Could not find table with {tableNumber}";
  101. }
  102.  
  103. var drink = drinks.FirstOrDefault(d => d.Name == drinkName && d.Brand == drinkBrand);
  104.  
  105. if (drink == null)
  106. {
  107. return $"There is no {drinkName} {drinkBrand} available";
  108. }
  109.  
  110. return $"Table {tableNumber} ordered {drinkName} {drinkBrand}";
  111. }
  112.  
  113. public string LeaveTable(int tableNumber)
  114. {
  115. var table = tables.FirstOrDefault(t => t.TableNumber == tableNumber);
  116.  
  117. table.Clear();
  118. var bill = table.GetBill();
  119. income += bill;
  120.  
  121. return $"Table: {tableNumber}" + Environment.NewLine +
  122. $"Bill: {income:f2}";
  123. }
  124.  
  125. public string GetFreeTablesInfo()
  126. {
  127. var sb = new StringBuilder();
  128.  
  129. foreach (var table in tables.Where(t => t.IsReserved == false))
  130. {
  131. sb.AppendLine(table.GetFreeTableInfo());
  132. }
  133.  
  134. return sb.ToString().TrimEnd();
  135. }
  136.  
  137. public string GetOccupiedTablesInfo()
  138. {
  139. var sb = new StringBuilder();
  140.  
  141. foreach (var table in tables.Where(t=>t.IsReserved == true))
  142. {
  143. sb.AppendLine(table.GetOccupiedTableInfo());
  144. }
  145.  
  146. return sb.ToString().TrimEnd();
  147. }
  148.  
  149. public string GetSummary()
  150. {
  151. return $"Total income: {this.income:f2}lv";
  152. }
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement