public IActionResult SearchByIngredients(RecipeSearchModel model)
        {
            var allRecipes = this.recipesService
                             .AllRecipesWithIngredients();

            var ingredients = model.Ingredients;

            var rating = new Dictionary <RecipeWithIngredients, int>();

            foreach (var rec in allRecipes)
            {
                rating.Add(rec, 0);
                foreach (var ingr in ingredients)
                {
                    if (rec.Ingredients.Contains(ingr))
                    {
                        rating[rec]++;
                    }
                }
            }

            var ordered = rating
                          .Where(o => o.Value > 0)
                          .OrderByDescending(r => r.Value);

            var recipes = ordered.Select(o => o.Key).ToList();

            return(PartialView("SearchResult", recipes));
        }
Ejemplo n.º 2
0
    private RecipeSearchModel ReadSearchModel()
    {
        RecipeSearchModel model = new RecipeSearchModel();

        try
        {
            if (RecipeCategory.SelectedValue != "0")
            {
                model.CategoryId = Convert.ToInt32(RecipeCategory.SelectedValue);
            }
        }
        catch (Exception ex)
        { }

        model.ItemsPerPage = GetItemsPerPage();
        model.Page         = GetCurrentPage();
        model.Keywords     = RecipeKeywords.Text;
        try
        {
            model.Page = Convert.ToDouble(CurrentPage.Value);
        }
        catch (Exception ex)
        { }

        model.SortBy             = RecipeSortByAdded.Checked ? RecipeSearchModel.SortOrder.RecentlyAdded : RecipeSearchModel.SortOrder.TopRated;
        model.WithoutIngredients = RecipeWithoutIngredients.Text;

        List <int> al = new List <int>();

        if (ChkEgg.Checked)
        {
            al.Add(4);
        }
        if (ChkFish.Checked)
        {
            al.Add(5);
        }
        if (ChkGluten.Checked)
        {
            al.Add(8);
        }
        if (ChkMilk.Checked)
        {
            al.Add(10);
        }
        if (ChkPeanut.Checked)
        {
            al.Add(15);
        }
        if (ChkSesame.Checked)
        {
            al.Add(20);
        }
        if (ChkShell.Checked)
        {
            al.Add(21);
        }
        if (ChkSoy.Checked)
        {
            al.Add(22);
        }
        if (ChkTree.Checked)
        {
            al.Add(26);
        }
        if (ChkWheat.Checked)
        {
            al.Add(27);
        }

        if (al.Count > 0)
        {
            model.AllerganFreeOfList = al.ToArray();
        }

        return(model);
    }
Ejemplo n.º 3
0
    private RecipeSearchResultModel SearchRecipies(RecipeSearchModel model)
    {
        DataAccess da = new DataAccess();

        return(da.SearchRecipes(model));
    }