-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WHQ7HJ - Éttermi rendeléskezelő #38
Open
Richard20a
wants to merge
4
commits into
CsharptutorialHungary:main
Choose a base branch
from
Richard20a:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.12.35514.174 d17.12 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WHQ7HJ", "WHQ7HJ\WHQ7HJ.csproj", "{FA2AA53F-5B1C-4B82-8499-D1F2973F734C}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FA2AA53F-5B1C-4B82-8499-D1F2973F734C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FA2AA53F-5B1C-4B82-8499-D1F2973F734C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FA2AA53F-5B1C-4B82-8499-D1F2973F734C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FA2AA53F-5B1C-4B82-8499-D1F2973F734C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace WHQ7HJ | ||
{ | ||
public record MenuItem(string Name, int Price); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace WHQ7HJ | ||
{ | ||
internal class MenuService | ||
{ | ||
private readonly string _filePath = "..\\..\\..\\menu.json"; | ||
|
||
|
||
public List<MenuItem> LoadMenu() | ||
{ | ||
try | ||
{ | ||
string json = File.ReadAllText(_filePath); | ||
return JsonSerializer.Deserialize<List<MenuItem>>(json) ?? new List<MenuItem>(); | ||
} | ||
catch(FileNotFoundException ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
Environment.Exit(1); | ||
return []; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
Environment.Exit(1); | ||
return []; | ||
} | ||
|
||
|
||
} | ||
|
||
public void DisplayMenu(List<MenuItem> menu) | ||
{ | ||
Console.WriteLine(""); | ||
Console.WriteLine("Menu"); | ||
Console.WriteLine("-----"); | ||
foreach (var item in menu) | ||
{ | ||
Console.WriteLine($"{item.Name} - {item.Price:C}"); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace WHQ7HJ | ||
{ | ||
public record Order(string CustomerName, string OrderDate, List<MenuItem> MenuItems); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace WHQ7HJ | ||
{ | ||
internal class OrderService | ||
{ | ||
|
||
private readonly string _filePath = "..\\..\\..\\orders.json"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Szintén csak Windows |
||
|
||
|
||
public List<Order> LoadOrders() | ||
{ | ||
try | ||
{ | ||
string json = File.ReadAllText(_filePath); | ||
return JsonSerializer.Deserialize<List<Order>>(json) ?? new List<Order>(); | ||
} | ||
catch (FileNotFoundException ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
return new List<Order>(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
return new List<Order>(); | ||
} | ||
|
||
} | ||
|
||
public Order CreateOrder(List<MenuItem> menu) | ||
{ | ||
Console.Write("Enter your name: "); | ||
string customerName = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(customerName)){ customerName = "Anonymous customer"; } | ||
|
||
string orderdate = DateTime.Today.ToString("dd/MM/yyyy"); | ||
|
||
var orderItems = new List<MenuItem>(); | ||
|
||
while (true) | ||
{ | ||
Console.Clear(); | ||
|
||
Console.WriteLine("Enter the name of the chosen dish (or 'OK' to finish): "); | ||
string input = Console.ReadLine(); | ||
|
||
if (input?.ToLower() == "ok") | ||
{ | ||
break; | ||
} | ||
|
||
var menuItem = menu.FirstOrDefault(item => item.Name.Equals(input, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (menuItem != null) | ||
{ | ||
orderItems.Add(menuItem); | ||
Console.WriteLine($"{menuItem.Name} added to the order."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("There is no such dish on the menu!"); | ||
} | ||
|
||
Console.WriteLine("Press any key to continue..."); | ||
Console.ReadKey(); | ||
} | ||
|
||
return new Order(customerName, orderdate, orderItems); | ||
} | ||
|
||
public void SaveOrders(List<Order> orders) | ||
{ | ||
try | ||
{ | ||
string json = JsonSerializer.Serialize(orders, new JsonSerializerOptions { WriteIndented = true }); | ||
File.WriteAllText(_filePath, json); | ||
} | ||
catch(IOException ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
Environment.Exit(1); | ||
} | ||
catch(Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
Environment.Exit(1); | ||
} | ||
} | ||
|
||
public void DisplayOrders(List<Order> orders) | ||
{ | ||
Console.WriteLine(""); | ||
Console.WriteLine("Orders"); | ||
Console.WriteLine("-----"); | ||
if(orders.Count == 0) | ||
{ | ||
Console.WriteLine("No order has been received yet."); | ||
} | ||
else | ||
{ | ||
foreach (var order in orders) | ||
{ | ||
Console.WriteLine($"Name: {order.CustomerName}, Date: {order.OrderDate}, Order: {string.Join(", ", order.MenuItems.Select(item => item.Name))}"); | ||
} | ||
} | ||
} | ||
|
||
public void DisplayPopularItems(List<Order> orders) | ||
{ | ||
if(orders.Count == 0) | ||
{ | ||
Console.WriteLine("No order has been received yet."); | ||
} | ||
else | ||
{ | ||
var popularItems = orders.SelectMany(order => order.MenuItems) | ||
.GroupBy(item => item.Name) | ||
.OrderByDescending(group => group.Count()) | ||
.Select(group => new { Item = group.Key, Count = group.Count() }); | ||
|
||
Console.WriteLine("Popular dishes"); | ||
Console.WriteLine("--------------"); | ||
foreach (var item in popularItems) | ||
{ | ||
Console.WriteLine($"{item.Item}: {item.Count} orders"); | ||
} | ||
} | ||
} | ||
|
||
public void CalculateTotal(List<Order> orders) | ||
{ | ||
Console.WriteLine($"Total revenue: {orders.Sum(order => order.MenuItems.Sum(item => item.Price))} Ft."); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using WHQ7HJ; | ||
|
||
var menuService = new MenuService(); | ||
var orderService = new OrderService(); | ||
|
||
var menu = menuService.LoadMenu(); | ||
var orders = orderService.LoadOrders(); | ||
|
||
while (true) | ||
{ | ||
Console.Clear(); | ||
Console.WriteLine("1. View menu"); | ||
Console.WriteLine("2. Place an order"); | ||
Console.WriteLine("3. View orders"); | ||
Console.WriteLine("4. Summary of orders"); | ||
Console.WriteLine("5. Exit"); | ||
|
||
Console.Write("Choose an option: "); | ||
string choice = Console.ReadLine(); | ||
|
||
switch (choice) | ||
{ | ||
case "1": | ||
menuService.DisplayMenu(menu); | ||
break; | ||
case "2": | ||
Order order = orderService.CreateOrder(menu); | ||
orders.Add(order); | ||
orderService.SaveOrders(orders); | ||
Console.WriteLine("Order recorded!"); | ||
break; | ||
case "3": | ||
orderService.DisplayOrders(orders); | ||
break; | ||
case "4": | ||
orderService.CalculateTotal(orders); | ||
orderService.DisplayPopularItems(orders); | ||
break; | ||
case "5": | ||
return; | ||
default: | ||
Console.WriteLine("Invalid choice!"); | ||
break; | ||
} | ||
|
||
Console.WriteLine("Press any key to continue..."); | ||
Console.ReadKey(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"Name": "Fried cheese", | ||
"Price": 1990 | ||
}, | ||
{ | ||
"Name": "Forest fruit soup", | ||
"Price": 880 | ||
}, | ||
{ | ||
"Name": "Bolognese pork chops", | ||
"Price": 2940 | ||
}, | ||
{ | ||
"Name": "Bean goulash soup", | ||
"Price": 1490 | ||
}, | ||
{ | ||
"Name": "Beef stew", | ||
"Price": 2350 | ||
}, | ||
{ | ||
"Name": "Spaghetti carbonara", | ||
"Price": 1990 | ||
}, | ||
{ | ||
"Name": "Fried catfish fillet", | ||
"Price": 2740 | ||
}, | ||
{ | ||
"Name": "Cabbage salad", | ||
"Price": 650 | ||
}, | ||
{ | ||
"Name": "Gundel pancakes", | ||
"Price": 450 | ||
} | ||
] |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ez csak windowson fog működni így