public ActionResult <IEnumerable <IngredientDto> > GetIngredients([FromQuery] IngredientParametersDto ingredientParametersDto)
        {
            var ingredientsFromRepo = _ingredientRepository.GetIngredients(ingredientParametersDto);

            var previousPageLink = ingredientsFromRepo.HasPrevious
                    ? CreateIngredientsResourceUri(ingredientParametersDto,
                                                   ResourceUriType.PreviousPage)
                    : null;

            var nextPageLink = ingredientsFromRepo.HasNext
                ? CreateIngredientsResourceUri(ingredientParametersDto,
                                               ResourceUriType.NextPage)
                : null;

            var paginationMetadata = new
            {
                totalCount  = ingredientsFromRepo.TotalCount,
                pageSize    = ingredientsFromRepo.PageSize,
                pageNumber  = ingredientsFromRepo.PageNumber,
                totalPages  = ingredientsFromRepo.TotalPages,
                hasPrevious = ingredientsFromRepo.HasPrevious,
                hasNext     = ingredientsFromRepo.HasNext,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationMetadata));

            var ingredientsDto = _mapper.Map <IEnumerable <IngredientDto> >(ingredientsFromRepo);

            return(Ok(ingredientsDto));
        }
예제 #2
0
        public Meal GetMeal(string userId, int mealId)
        {
            DataTable mealTable        = _mealRepository.GetMeal(mealId);
            DataTable ingredientsTable = _ingredientRepository.GetIngredients(userId, mealId);

            return(_mealMapper.HydrateMeal(mealTable, ingredientsTable).FirstOrDefault());
        }
예제 #3
0
        public IActionResult Index()
        {
            RecipeModel model = _recipeRepository.GetRecipe(_settings.FeaturedRecipeID);

            model.Ingredients = _ingredientRepository.GetIngredients(_settings.FeaturedRecipeID);
            model.Steps       = _stepsRepository.GetSteps(_settings.FeaturedRecipeID);
            return(View(model));
        }
        public IActionResult Index()
        {
            var ingredients = _ingredientRepository.GetIngredients();

            if (ingredients.Count() <= 0)
            {
                ViewBag.Message = "There was a problem retrieving ingredients from database or no ingredient exists";
            }
            return(View(ingredients));
        }
예제 #5
0
 /// <summary>
 /// Method gets all ingredients of some dish
 /// </summary>
 /// <param name="dishId">Id of the dish, that contains ingredients</param>
 /// <returns>List of <IngredientModel></returns>
 public IEnumerable <IngredientModel> GetIngredients(int dishId)
 {
     try
     {
         return(_ingredientRepository.GetIngredients(dishId));
     }
     catch (Exception ex)
     {
         throw new Exception("Error while getting ingredients: " + ex.Message, ex);
     }
 }
예제 #6
0
        public IActionResult DisplayRecipe(int ID)
        {
            RecipeModel model = null;

            if (ModelState.IsValid)
            {
                model             = _recipeRepository.GetRecipe(ID);
                model.Ingredients = _ingredientRepository.GetIngredients(ID);
                model.Steps       = _stepsRepository.GetSteps(ID);
            }
            return(View(model));
        }
예제 #7
0
        private async Task <DialogTurnResult> AskForIngredientConfirmationAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (await ShouldCancelDialogsAsync(stepContext.Context, cancellationToken))
            {
                return(await stepContext.CancelAllDialogsAsync());
            }

            var orderInfo = await _orderInfo.GetAsync(stepContext.Context);

            var userIngredients     = (string)stepContext.Result;
            var existingIngredients = _ingredientRepository.GetIngredients().OrderByDescending(i => i.Name.Length).ToList();
            var addedIngredients    = new List <Ingredient>();

            foreach (var ingredient in existingIngredients)
            {
                var ingredientIndex = userIngredients.IndexOf(ingredient.Name);
                if (ingredientIndex >= 0)
                {
                    addedIngredients.Add(ingredient);
                    userIngredients = userIngredients.Remove(ingredientIndex, ingredient.Name.Length);
                }
            }

            if (!addedIngredients.Any())
            {
                await SendMessageAsync(stepContext.Context, "Lo siento, pero ninguno de los ingredientes que me has dicho están en nuestra base de datos. Recuerda que los ingredientes que te ofrecemos son: " +
                                       existingIngredients.OrderBy(i => i.Name).Select(i => i.Name).ToArray().ConcatenateWith("y") + ".", cancellationToken);

                return(await stepContext.ReplaceDialogAsync("WaterfallDialog", orderInfo));
            }
            var pizza = new Pizza {
                Ingredients = addedIngredients, Name = "Una pizza personalizada"
            };

            orderInfo.Pizzas.Add(pizza);

            var message = "He entendido que quieres una pizza de " +
                          addedIngredients.Select(i => i.Name).ToArray().ConcatenateWith("y") + ".";
            var retryPrompt = "¿Perdona? No sé si eso es un sí o es un no. " +
                              message;
            await _orderInfo.SetAsync(stepContext.Context, orderInfo);

            return(await stepContext.PromptAsync("ConfirmIngredients", new PromptOptions
            {
                Prompt = MessageFactory.Text(message, message),
                RetryPrompt = MessageFactory.Text(retryPrompt, retryPrompt),
            }, cancellationToken));
        }
예제 #8
0
        public async Task <IActionResult> Get()
        {
            try
            {
                var result = await _iIngredientRepository.GetIngredients();

                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
예제 #9
0
        public IActionResult GetIngredients()
        {
            var ingredients = _ingredientRepository.GetIngredients().ToList();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ingredientsDto = new List <IngredientDto>();

            foreach (var ingredient in ingredients)
            {
                ingredientsDto.Add(new IngredientDto
                {
                    Id       = ingredient.Id,
                    Name     = ingredient.Name,
                    Quantity = ingredient.Quantity
                });
            }
            return(Ok(ingredientsDto));
        }
예제 #10
0
        public List <Ingredient> GetIngredients()
        {
            var ingredients = _ingredientsRepository.GetIngredients();

            return(ingredients);
        }
        public IActionResult Index()
        {
            var model = _ingredientRepository.GetIngredients();

            return(View(model));
        }