public void Serve(Task task) { //TODO: Why this method has 'task' parameter? Should we use it? //TODO: This method is too long. Can you make it small? The way to make it smaller is to use LINQ instead of 'foreach'... if (served) { throw new Exception("Customers already served!"); } if (!sendedToCook) { throw new Exception("You didn't cook!"); } foreach (KeyValuePair <string, List <IMenuItem> > row in tableRequests) { int ch = row.Value.Count(r => r is Chicken); int e = row.Value.Count(r => r is Egg); Type t = row.Value.Where(r => r is Drink).First().GetType(); var str = $"Customer {row.Key} is served {ch} chicken, {e} egg, "; if (t != null) { str += $"{t.Name}"; } else { str += "no drinks"; } resultOfCooks.Add(str); } served = false; tableRequests.Clear(); }
public void Processed(TableRequests tableRequests) { foreach (KeyValuePair <string, List <IMenuItem> > row in tableRequests) { var ch = 0; var e = 0; Type t = null; foreach (IMenuItem value in row.Value) { if (value is Chicken) { ch++; } else if (value is Egg) { e++; } else if (value is Drink) { t = value.GetType(); } } var str = $"Customer {row.Key} is served {ch} chicken, {e} egg, "; if (t != null) { str += $"{t.Name}"; } else { str += "no drinks"; } resultOfCooks.Add(str); } served = false; tableRequests.Clear(); }