/// <summary> /// Get filtered types of dishes /// </summary> /// <param name="opcs">string options</param> /// <param name="time">string mealtime</param> /// <returns></returns> public List <Dishes> GetByDishType(string opcs, string time) { List <Dishes> listDishes = GetAll(); Dishes newDishes; List <Dishes> listNewDishes = new List <Dishes>(); try { foreach (var item in opcs.Split(new char[] { ',' })) { int opc = Convert.ToInt32(item); newDishes = listDishes.FirstOrDefault(x => x.mealTime.ToString().Equals(time) && x.mealType.Equals(opc)); if ((newDishes == null) || listNewDishes.Any(x => x.mealType.Equals(newDishes.mealType) && !newDishes.allowMultiple)) { newDishes = new Dishes(); newDishes.error.hasError = true; newDishes.error.detail = "error"; newDishes.mealType = listNewDishes.Count + 1; listNewDishes.Add(newDishes); return(listNewDishes); } if (listNewDishes.Any(x => x.mealType.Equals(newDishes.mealType)) && newDishes.allowMultiple) { listNewDishes.Remove(newDishes); newDishes.qtd += listNewDishes.Count(x => x.mealType.Equals(newDishes.mealType)) + 1; } listNewDishes.Add(newDishes); } } catch (Exception) { throw new Exception(); } return(listNewDishes); }
/// <summary> /// Get filtered types of dishes /// </summary> /// <param name="opcs">string options</param> /// <param name="time">string mealtime</param> /// <returns></returns> public List<Dishes> GetByDishType(string opcs, string time) { List<Dishes> listDishes = GetAll(); Dishes newDishes; List<Dishes> listNewDishes = new List<Dishes>(); try { foreach (var item in opcs.Split(new char[] { ',' })) { int opc = Convert.ToInt32(item); newDishes = listDishes.FirstOrDefault(x => x.mealTime.ToString().Equals(time) && x.mealType.Equals(opc)); if ((newDishes == null) || listNewDishes.Any(x => x.mealType.Equals(newDishes.mealType) && !newDishes.allowMultiple)) { newDishes = new Dishes(); newDishes.error.hasError = true; newDishes.error.detail = "error"; newDishes.mealType = listNewDishes.Count + 1; listNewDishes.Add(newDishes); return listNewDishes; } if (listNewDishes.Any(x => x.mealType.Equals(newDishes.mealType)) && newDishes.allowMultiple) { listNewDishes.Remove(newDishes); newDishes.qtd += listNewDishes.Count(x => x.mealType.Equals(newDishes.mealType)) + 1; } listNewDishes.Add(newDishes); } } catch (Exception) { throw new Exception(); } return listNewDishes; }