-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeamFoodMenu.cs
201 lines (168 loc) · 5.45 KB
/
TeamFoodMenu.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using System.Text;
namespace TeamFoodCrawler
{
[Flags]
public enum FoodType {Andere = 0, Schwein = 1, Rind = 2, Vegetarisch = 4, Geflügel = 8, Fisch = 16};
public enum Wochentage { Montag, Dienstag, Mittwoch, Donnerstag, Freitag };
// *****************************************
// Ein Speiseplan für eine Woche
// *****************************************
class TeamFoodMenu
{
private int kw;
private DateTime startDate;
private DateTime endDate;
private List<TeamFoodDay> days;
public List<TeamFoodDay> Days
{
get { return days; }
set { days = value; }
}
public int KW
{
get { return kw; }
set { kw = value; }
}
public DateTime StartDate
{
get { return startDate; }
set { startDate = value; }
}
public DateTime EndDate
{
get { return endDate; }
set { endDate = value; }
}
public TeamFoodMenu(int kw, DateTime start, DateTime end)
{
// Guard Clause
if(start == null | end == null | kw > 52)
{
throw new Exception("Falsche Übergabedaten an Kosturktor zu TeamFoodMenu");
}
KW = kw;
StartDate = start;
EndDate = end;
days = new List<TeamFoodDay>();
}
public void AddMenuItem(Wochentage day, TeamFoodMenuItem menuItem)
{
if (menuItem == null) throw new Exception("Falsche Daten für MenuItem");
if (!Enum.IsDefined(typeof(Wochentage), day)) throw new Exception("Ungültiger Wochentag angegeben.");
TeamFoodDay teamFoodDay;
teamFoodDay = days.Find(x => x.Wochentag == day);
if (teamFoodDay == null)
{
teamFoodDay = new TeamFoodDay(day);
days.Add(teamFoodDay);
}
teamFoodDay.AddMenuItem(menuItem);
}
// Gibt den Speiseplan als Text aus
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendFormat("TeamFood Speiseplan für KW {0} ({1} - {2})\n", KW.ToString(), StartDate.ToShortDateString(), EndDate.ToShortDateString());
sb.AppendLine(new String('=', 55));
sb.AppendLine();
foreach (var d in Days)
{
sb.Append(d.ToString());
sb.AppendLine();
}
return sb.ToString();
}
}
// *****************************************
// Ein Tag bei TeamFood
// *****************************************
public class TeamFoodDay
{
private Wochentage weekday;
private List<TeamFoodMenuItem> menuItems;
public Wochentage Wochentag
{
get { return weekday; }
set { weekday = value; }
}
public List<TeamFoodMenuItem> MenuItems
{
get { return menuItems; }
set { menuItems = value; }
}
public TeamFoodDay(Wochentage tag)
{
if (!Enum.IsDefined(typeof(Wochentage), tag)) throw new Exception("Falscher Wochentag angegeben.");
Wochentag = tag;
menuItems = new List<TeamFoodMenuItem>();
}
public void AddMenuItem(TeamFoodMenuItem menuItem)
{
if (menuItem == null ) throw new Exception("Falsche Daten für MenuItem");
menuItems.Add(menuItem);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}:\n", weekday);
foreach(var mi in menuItems)
{
sb.Append(mi.ToString());
sb.AppendLine();
}
return sb.ToString();
}
}
// *****************************************
// Ein einzelner Eintrag in die Speiseliste
// *****************************************
public class TeamFoodMenuItem
{
private List<int> additives;
private string description;
private decimal price;
private FoodType type;
private string sideDish;
public List<int> Additives
{
get { return additives; }
set { additives = value; }
}
public FoodType Type
{
get { return type; }
set { type = value; }
}
public decimal Price
{
get { return price; }
set { price = value; }
}
public string Description
{
get { return description; }
set
{
description = value.Replace(" ", " ");
}
}
public string SideDish
{
get { return sideDish; }
set { sideDish = value; }
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}\n", description);
if (SideDish != String.Empty && SideDish != "-") sb.AppendFormat("{0}\n", SideDish);
sb.AppendFormat("{0}€ / {1} / ", price, type);
var additivesList = string.Join(", ", additives);
sb.AppendFormat("Zusätze: {0}\n", additivesList);
return sb.ToString();
}
}
}