Esempio n. 1
0
        public IActionResult GetRecipeCount(RamseyLocale locale = RamseyLocale.Swedish)
        {
            var count = _ramseyContext.Recipes.Where(x => x.Locale == locale)
                        .Count();

            return(Json(count));
        }
Esempio n. 2
0
        public IActionResult Suggest(RamseyLocale locale = RamseyLocale.Swedish)
        {
            Random rand = new Random();
            var    skip = (int)(rand.NextDouble() * _ramseyContext.Tags.Count());

            var tags = _ramseyContext.Tags
                       .AsNoTracking()
                       .OrderBy(x => x.TagId)
                       .Skip(skip)
                       .Where(x => x.Locale == locale)
                       .Include(x => x.RecipeTags)
                       .ThenInclude(x => x.Recipe)
                       .Take(10);

            List <TagDto> dtos = new List <TagDto>();

            foreach (var tag in tags)
            {
                var headerRecipe = tag.RecipeTags.OrderBy(x => Guid.NewGuid()).FirstOrDefault()?.Recipe;

                if (headerRecipe != null)
                {
                    dtos.Add(new TagDto
                    {
                        Name         = tag.Name,
                        PreviewImage = headerRecipe.Image,
                        TagId        = tag.TagId
                    });
                }
            }

            return(Json(dtos));
        }
        public IActionResult Text(string search, int start = 0, RamseyLocale locale = RamseyLocale.Swedish)
        {
            var recipes = _ramseyContext.Recipes
                          .Where(x => EF.Functions.Like(x.Name, $"%{search}%"))
                          .Where(x => x.Locale == locale)
                          .OrderBy(x => x.Name)
                          .Skip(start)
                          .Take(25);

            return(Json(recipes));
        }
        public IActionResult Suggest(string search, RamseyLocale locale = RamseyLocale.Swedish)
        {
            var ingredients     = _ramseyContext.Ingredients.Where(x => x.IngredientName.Contains(search)).Include(x => x.RecipeParts).ToList();
            var ingredientsDtos = ingredients.Select(x => new IngredientDto
            {
                RecipeParts = x.RecipeParts.Select(y => new RecipePartDto
                {
                    IngredientId = y.IngredientId,
                    RecipeId     = y.RecipeId
                }).ToList(),
                IngredientId = x.IngredientName
            }).ToList();

            return(Json(ingredientsDtos));
        }
Esempio n. 5
0
        public IActionResult Suggest(string search, RamseyLocale locale = RamseyLocale.Swedish)
        {
            var ingredients = _ramseyContext.Ingredients
                              .Where(x => EF.Functions.Like(x.IngredientName, $"%{search}%"))
                              .OrderBy(x => x.IngredientName.Length)
                              .Take(10);

            var ingredientsDtos = ingredients.Select(x => new IngredientDtoV2
            {
                IngredientId   = x.IngredientId,
                IngredientName = x.IngredientName,
                Role           = IngredientRole.Include
            });

            return(Json(ingredientsDtos));
        }