Esempio n. 1
0
        public void OnGet()
        {
            var recipes = _dbContext.Recipes
                          .FromSqlRaw("Select * from Recipes where IsDrink = 0");


            Recipes.AddRange(_dbContext.Recipes);
            Recipes = recipes.ToList();
            Recipes = RandomList.Randomize(Recipes).ToList();
            foreach (var r in Recipes)
            {
                var ingredients = _dbContext.Ingredients
                                  .Where(i => i.RecipeId == r.RecipeId);
                r.Ingredients = ingredients.ToList();
            }
        }
Esempio n. 2
0
        public void Randomizing()
        {
            // Arrange
            var randList = new RandomList <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };
            var randListBeforeRandomize = randList.ToArray();
            var equalValues             = new bool[10];

            // Act
            randList.Randomize();

            // Assert
            for (int i = 0; i < randList.Count; i++)
            {
                equalValues[i] = randList[i] == randListBeforeRandomize[i];
            }

            // Ok if contains any false value
            Assert.Contains(equalValues, v => !v);
        }
Esempio n. 3
0
        public async Task <IActionResult> OnGet()
        {
            var recipes = _dbContext.Recipes
                          .FromSqlRaw("Select * from Recipes where IsDrink = 1");

            Recipes.AddRange(_dbContext.Recipes);
            foreach (var r in Recipes)
            {
                var ingredients = _dbContext.Ingredients
                                  .Where(i => i.RecipeId == r.RecipeId);
                r.Ingredients = ingredients.ToList();
            }

            Recipes = recipes.ToList();
            Recipes = RandomList.Randomize(Recipes).ToList();
            if (Recipes == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            string searchString = Request.Form["searchString"];

            if (searchString == "")
            {
                Response.Redirect("Index");
                return(Page());
            }

            if (searchString == "likes")
            {
                var recipe = _dbContext.Recipes
                             .FromSqlRaw("Select * from Recipes where NumberOfLikes != 0");
                Recipes.AddRange(_dbContext.Recipes);

                foreach (var r in Recipes)
                {
                    var ingredients = _dbContext.Ingredients
                                      .Where(i => i.RecipeId == r.RecipeId);
                    r.Ingredients = ingredients.ToList();
                }

                Recipes = recipe.ToList();
                return(Page());
            }

            string ingQueryString = null;
            bool   first          = true;

            searchString.Trim();
            List <string> searchStringList =
                searchString.Split(new char[0],
                                   StringSplitOptions.RemoveEmptyEntries).ToList();

            foreach (var i in searchStringList)
            {
                if (first)
                {
                    ingQueryString += " Description LIKE '%" + i + "%'";
                    first           = false;
                }
                else
                {
                    ingQueryString += " AND Description LIKE '%" + i + "%'";
                }
            }
            //var recipeIds =  _dbContext.Ingredients.
            //    FromSqlRaw("Select RecipeId from Ingredients where"
            //        + ingQueryString);
            var recipes = _dbContext.Recipes
                          .FromSqlRaw("Select * from Recipes where RecipeId in " +
                                      "(Select RecipeId from Ingredients where" + ingQueryString +
                                      /*+ recipeIds +*/ ")");

            Recipes.AddRange(_dbContext.Recipes);
            foreach (var r in Recipes)
            {
                var ingredients = _dbContext.Ingredients
                                  .Where(i => i.RecipeId == r.RecipeId);
                r.Ingredients = ingredients.ToList();
            }

            Recipes = recipes.ToList();
            Recipes = RandomList.Randomize(Recipes).ToList();
            if (Recipes == null)
            {
                return(NotFound());
            }
            return(Page());
        }