public List <DishResponse> Get(string _choices)
        {
            List <DishResponse> response = new List <DishResponse>();


            if (_choices != null)
            {
                Mealtime     mealtime;
                DishResponse dishResponse = new DishResponse();
                dishResponse.Input = _choices;

                //first comma
                int fc = _choices.IndexOf(",");

                try{
                    //Find Mealtime inside input
                    mealtime = _requestDishes.ValidateMealtime(_choices, fc);
                    //Find Meals, ordenate list and create a string for output
                    dishResponse.Output = _requestDishes.ValidateOutput(_choices, fc, mealtime);
                }
                catch
                {
                    response.Add(new DishResponse("error", dishResponse.Input));
                    return(response);
                }

                response.Add(dishResponse);
            }



            return(response);
        }
Esempio n. 2
0
        public JArray getAllDishes(List <Dish> dishes, List <Ingredients> ingredients)
        {
            /*
             * return JArray with all the dishes, sorted by name and lastupdatedOn
             */

            List <DishResponse> dishResponsesList = new List <DishResponse>();

            foreach (Dish dish in dishes)
            {
                DishResponse dishResponse = new DishResponse();

                List <IngredientResponse> ingredientResponseList = new List <IngredientResponse>();

                dishResponse.id            = dish.id;
                dishResponse.name          = dish.name;
                dishResponse.lastupdatedOn = dish.updatedOn;

                foreach (Ingredient ingredient in dish.ingredients)
                {
                    if (ingredients.Exists(x => x.id == ingredient.ingredientId))
                    {
                        Ingredients current = ingredients.Find(x => x.id == ingredient.ingredientId);

                        IngredientResponse ingredientResponse = new IngredientResponse();

                        ingredientResponse.id   = current.id;
                        ingredientResponse.name = current.name;

                        ingredientResponseList.Add(ingredientResponse);
                    }
                }
                dishResponse.ingredients = ingredientResponseList;
                dishResponsesList.Add(dishResponse);
            }

            List <DishResponse> filterList = dishResponsesList.OrderBy(x => x.name).ThenBy(x => x.lastupdatedOn).ToList();
            string json = JsonConvert.SerializeObject(filterList);

            return(JArray.Parse(json));
        }