public void GetOrder(Order order) { if(order.DishTypes.Where(x => x == DishType.Dessert).Count() > 0) { order.ErrorMessage = "Invalid Order."; } }
public void GetOrder(Order order) { if (order.DishTypes.Where(x => x == DishType.Invalid).Count() > 0) { order.ErrorMessage = "Invalid Selection"; } }
public void GetOrder(Order order) { var drinkQuery = order.DishTypes.Where(x => x == DishType.Drink); if(drinkQuery.Count() > 0) { List<string> drinkItems = new List<string>(); foreach (var dType in drinkQuery) { drinkItems.Add(FoodItems.Coffee.ToString()); } order.ReturnOrders.Add(DishType.Drink, drinkItems); } }
private Order BuildOrder(string[] orderParams) { List<string> lstOrdParams = orderParams.ToList(); Order inpurOrder = new Order(); TimeOfDay timeOfDay = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), lstOrdParams[0].ToUpper()); inpurOrder.TimeOfDay = timeOfDay; inpurOrder.DishTypes = new List<DishType>(); //*** //*** remove the last value from the input array if empty //*** if(string.IsNullOrWhiteSpace(lstOrdParams.Skip(1).Last().ToString())) { lstOrdParams.RemoveAt(lstOrdParams.Count()-1); } foreach (var itemId in lstOrdParams.Skip(1)) { DishType _dtype; int intEnumValue; if (Int32.TryParse(itemId, out intEnumValue)) { if (Enum.IsDefined(typeof(DishType), intEnumValue)) { _dtype = (DishType)(object)intEnumValue; } else { _dtype = DishType.Invalid; } } else { throw new InvalidCastException("Invalid selection."); } inpurOrder.DishTypes.Add(_dtype); } return inpurOrder; }
public void GetOrder(Order order) { List<string> dessertItems = new List<string>() { FoodItems.Cake.ToString() }; foreach (var dType in order.DishTypes.Where(x => x == DishType.Dessert)) { var existingOrder = order.ReturnOrders.Where(x => x.Key == DishType.Dessert); if (existingOrder.Count() > 1) { order.ErrorMessage = "Can not order more than one Dessert."; } else { order.ReturnOrders.Add(dType, dessertItems); } } }
public void GetOrder(Order order) { List<string> entreeItems = new List<string>() { FoodItems.Steak.ToString() }; foreach (var dType in order.DishTypes.Where(x => x == DishType.Entree)) { var existingOrder = order.ReturnOrders.Where(x => x.Key == DishType.Entree); if (existingOrder.Count() > 0) { order.ErrorMessage = "Can not order more than one Entree."; } else { order.ReturnOrders.Add(dType, entreeItems); } } }
private string GenerateFormattedOutput(Order order) { StringBuilder formattedStringOutput = new StringBuilder(); formattedStringOutput.Append("output: "); String prefix = ""; foreach (var item in order.ReturnOrders) { formattedStringOutput.Append(prefix); prefix = ","; formattedStringOutput.Append(item.Value[0].ToLower()); if (item.Value.Count() > 1) { formattedStringOutput.Append(string.Format("(x{0})", item.Value.Count())); } } if (!string.IsNullOrWhiteSpace(order.ErrorMessage)) { formattedStringOutput.Append(prefix); formattedStringOutput.Append("error"); } return formattedStringOutput.ToString(); }