Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SoftUniRestaurant.Core
- {
- using SoftUniRestaurant.Factories;
- using SoftUniRestaurant.Models.Drinks.Contracts;
- using SoftUniRestaurant.Models.Foods.Contracts;
- using SoftUniRestaurant.Models.Tables.Contracts;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class RestaurantController
- {
- private List<IFood> menu;
- private List<IDrink> drinks;
- private List<ITable> tables;
- private FoodFactory foodFactory;
- private DrinkFactory drinkFactory;
- private TableFactory tableFactory;
- private decimal income;
- public RestaurantController()
- {
- this.menu = new List<IFood>();
- this.drinks = new List<IDrink>();
- this.tables = new List<ITable>();
- this.foodFactory = new FoodFactory();
- this.drinkFactory = new DrinkFactory();
- this.tableFactory = new TableFactory();
- this.income = 0;
- }
- public string AddFood(string type, string name, decimal price)
- {
- var food = foodFactory.CreateFood(type, name, price);
- menu.Add(food);
- return $"Added {name} ({type}) with price {price:f2} to the pool";
- }
- public string AddDrink(string type, string name, int servingSize, string brand)
- {
- var drink = drinkFactory.CreateDrink(type, name, servingSize, brand);
- drinks.Add(drink);
- return $"Added {name} ({brand}) to the drink pool";
- }
- public string AddTable(string type, int tableNumber, int capacity)
- {
- var table = tableFactory.CreateTable(type, tableNumber, capacity);
- tables.Add(table);
- return $"Added table number {tableNumber} in the restaurant";
- }
- public string ReserveTable(int numberOfPeople)
- {
- ITable freeTable = tables.FirstOrDefault(t => t.IsReserved == false && t.NumberOfPeople >= numberOfPeople);
- if (freeTable == null)
- {
- return $"No available table for {numberOfPeople} people";
- }
- freeTable.Reserve(numberOfPeople);
- return $"Table {freeTable.TableNumber} has been reserved for {numberOfPeople} people";
- }
- public string OrderFood(int tableNumber, string foodName)
- {
- var table = tables.FirstOrDefault(t => t.TableNumber == tableNumber);
- if (table == null)
- {
- return $"Could not find table with {tableNumber}";
- }
- var food = menu.FirstOrDefault(f => f.Name == foodName);
- if (food == null)
- {
- return $"No {foodName} in the menu";
- }
- return $"Table {tableNumber} ordered {foodName}";
- }
- public string OrderDrink(int tableNumber, string drinkName, string drinkBrand)
- {
- var table = tables.FirstOrDefault(t => t.TableNumber == tableNumber);
- if (table == null)
- {
- return $"Could not find table with {tableNumber}";
- }
- var drink = drinks.FirstOrDefault(d => d.Name == drinkName && d.Brand == drinkBrand);
- if (drink == null)
- {
- return $"There is no {drinkName} {drinkBrand} available";
- }
- return $"Table {tableNumber} ordered {drinkName} {drinkBrand}";
- }
- public string LeaveTable(int tableNumber)
- {
- var table = tables.FirstOrDefault(t => t.TableNumber == tableNumber);
- table.Clear();
- var bill = table.GetBill();
- income += bill;
- return $"Table: {tableNumber}" + Environment.NewLine +
- $"Bill: {income:f2}";
- }
- public string GetFreeTablesInfo()
- {
- var sb = new StringBuilder();
- foreach (var table in tables.Where(t => t.IsReserved == false))
- {
- sb.AppendLine(table.GetFreeTableInfo());
- }
- return sb.ToString().TrimEnd();
- }
- public string GetOccupiedTablesInfo()
- {
- var sb = new StringBuilder();
- foreach (var table in tables.Where(t=>t.IsReserved == true))
- {
- sb.AppendLine(table.GetOccupiedTableInfo());
- }
- return sb.ToString().TrimEnd();
- }
- public string GetSummary()
- {
- return $"Total income: {this.income:f2}lv";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement