コード例 #1
0
        public IActionResult OnGet(string message)
        {
            var categories = this.categoryData.GetAll().Select(c => new SelectListItem {
                Value = c.Id, Text = c.Name
            }).ToList();

            categories.Insert(0, new SelectListItem {
                Value = string.Empty, Text = string.Empty
            });

            Categories = categories;

            var minGroupServings = new SelectListGroup {
                Name = ServingOptions.ServingsSmall.Description
            };
            var mediumGroupServings = new SelectListGroup {
                Name = ServingOptions.ServingsMedium.Description
            };
            var largeGroupServings = new SelectListGroup {
                Name = ServingOptions.ServingsLarge.Description
            };

            var servings = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = string.Empty, Text = string.Empty
                },
                new SelectListItem {
                    Value = ServingOptions.ServingsSmall.HighEnd.ToString(), Text = $"{ServingOptions.ServingsSmall.HighEnd.ToString()} servings", Group = minGroupServings
                },
                new SelectListItem {
                    Value = ServingOptions.ServingsMedium.HighEnd.ToString(), Text = $"{ServingOptions.ServingsMedium.HighEnd.ToString()} servings", Group = mediumGroupServings
                },
                new SelectListItem {
                    Value = ServingOptions.ServingsLarge.LowEnd.ToString(), Text = $"{ServingOptions.ServingsLarge.LowEnd.ToString()} servings", Group = largeGroupServings
                }
            };

            Servings = servings;

            if (IsSearchValidationError(message))
            {
                return(Page());
            }


            var model = new MenuRecipeSearchModel {
                CookTimeSelected = CookTime, ServingsSelected = ServingNumber, RecipeNameSelected = RecipeName, IngredientsSelected = Ingredients?.Split(",").ToList(), CategorySelectedId = CategoryId
            };

            return(RedirectToPage("List", "FilteredSearch", model));
        }
コード例 #2
0
        public IActionResult OnGetFilteredSearch(MenuRecipeSearchModel menuRecipeSearchModel)
        {
            List <Recipe> recipesFiltered = new List <Recipe>();

            FilterValue[] filters = new FilterValue[menuRecipeSearchModel.CountOfFiltersApplied];

            int filterCount = 0;

            filterCount = ApplyFilter(menuRecipeSearchModel.IsCookTimeEntered, FilterType.EQUAL, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.CookTimeMinutes), new List <string> {
                menuRecipeSearchModel.CookTimeSelected?.ToString()
            }, filters, filterCount);
            filterCount = ApplyFilter(menuRecipeSearchModel.IsRecipeEntered, FilterType.LIKE, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Name), new List <string> {
                menuRecipeSearchModel.RecipeNameSelected
            }, filters, filterCount);
            filterCount = ApplyFilter(menuRecipeSearchModel.IsIngredientsEntered, FilterType.LIKE, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Ingredients), menuRecipeSearchModel.IngredientsSelected, filters, filterCount);
            filterCount = ApplyFilter(menuRecipeSearchModel.IsCategoryEntered, FilterType.EQUAL, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.CategoryId), new List <string> {
                menuRecipeSearchModel.CategorySelectedId
            }, filters, filterCount);

            //TODO: MONGO CRUD for range filter, less than, greater than, REFACTOR RANGE PASSED PARAMETERS TO GENERIC MONGO REPOSITORY CLASS FUNCTION
            if (menuRecipeSearchModel.IsServingsSelected)
            {
                ServingRangeModel servingOptions = new ServingRangeModel();
                if (servingOptions.ServingsSmall.HighEnd == int.Parse(menuRecipeSearchModel.ServingsSelected))
                {
                    filterCount = ApplyFilter(menuRecipeSearchModel.IsServingsSelected, FilterType.LESS_THAN_EQUAL, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Servings), new List <string> {
                        servingOptions.ServingsSmall.HighEnd.ToString()
                    }, filters, filterCount);
                }
                else if (servingOptions.ServingsMedium.HighEnd == int.Parse(menuRecipeSearchModel.ServingsSelected))
                {
                    filterCount = ApplyFilter(menuRecipeSearchModel.IsServingsSelected, FilterType.RANGE, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Servings), new List <string> {
                        servingOptions.ServingsMedium.LowEnd.ToString(), servingOptions.ServingsMedium.HighEnd.ToString()
                    }, filters, filterCount);
                }
                else if (servingOptions.ServingsLarge.LowEnd == int.Parse(menuRecipeSearchModel.ServingsSelected))
                {
                    filterCount = ApplyFilter(menuRecipeSearchModel.IsServingsSelected, FilterType.GREATER_THAN_EQUAL, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Servings), new List <string> {
                        servingOptions.ServingsLarge.LowEnd.ToString()
                    }, filters, filterCount);
                }
            }
            //filterCount = ApplyFilter(menuRecipeSearchModel.IsServingsSelected, FilterType.RANGE, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Servings), new List<string> { "8", "10" }, filters, filterCount);

            //filterCount = ApplyFilter(menuRecipeSearchModel.IsServingsSelected, FilterType.RANGE, Enum.GetName(typeof(CollectionMappings.RecipeFields), CollectionMappings.RecipeFields.Servings), new List<string> { menuRecipeSearchModel.ServingsSelected }, filters, filterCount);


            recipesFiltered = this.recipeData.GetByOr(filters);


            if (recipesFiltered.Count == 0)
            {
                return(RedirectToPage("Search", new { message = "No menu recipe(s) found based on search" }));
            }

            Recipes = recipesFiltered.Select(x => new RecipeModel {
                RecipeId = x.Id, CategoryName = this.categoryData.GetById(x.CategoryId)?.Name, RecipeName = x.Name
            }).OrderBy(x => x.CategoryName).ThenBy(x => x.RecipeName);

            return(Page());
        }