Пример #1
0
        public ActionResult ShowSearchResult(string searchRecipeName, string searchCategoryName, string searchIngridientName)
        {
            SearchViewModel model = new SearchViewModel();

            model.RecipeModel = new ShortRecipeViewModel();
            List <RecipeView> recipes = _recipeProvider.GetRecipes();

            model.Header = "";
            IEnumerable <RecipeView> recipesR = null;
            IEnumerable <RecipeView> recipesC = null;
            IEnumerable <RecipeView> recipesI = null;

            if (!string.IsNullOrEmpty(searchRecipeName))
            {
                recipesR     = _recipeProvider.GetRecipesByRecipeName(searchRecipeName);
                model.Header = model.Header + "Searching \"" + searchRecipeName + "\" in Recipes \n";
            }
            if (!string.IsNullOrEmpty(searchCategoryName))
            {
                recipesC     = _recipeProvider.GetRecipesByCategoryName(searchCategoryName);
                model.Header = model.Header + "Searching \"" + searchCategoryName + "\" in Categories \n";
            }
            if (!string.IsNullOrEmpty(searchIngridientName))
            {
                recipesI     = _recipeProvider.GetRecipesByIngridientName(searchIngridientName);
                model.Header = model.Header + "Searching \"" + searchIngridientName + "\" in Ingridients \n";
            }

            if (recipesR == null && recipesC == null && recipesI == null)
            {
                model.RecipeModel.Recipes = null;
            }
            else
            {
                if (recipesR != null)
                {
                    recipes.RemoveAll(r1 => recipesR.FirstOrDefault(r2 => r2.RecipeId == r1.RecipeId) == null);
                }

                if (recipesC != null)
                {
                    recipes.RemoveAll(r1 => recipesC.FirstOrDefault(r2 => r2.RecipeId == r1.RecipeId) == null);
                }

                if (recipesI != null)
                {
                    recipes.RemoveAll(r1 => recipesI.FirstOrDefault(r2 => r2.RecipeId == r1.RecipeId) == null);
                }

                model.RecipeModel.Recipes = recipes;
            }

            return(PartialView("_SearchResult", model));
        }
Пример #2
0
        // GET: Category

        public ActionResult Index(int?page)
        {
            IEnumerable <SelectItemViewModel> categoriesList = new List <SelectItemViewModel>();

            categoriesList     = _recipeProvider.GetSelectCategories();
            ViewBag.CategoryId = new SelectList(categoriesList, "Id", "Name");


            var model      = _recipeProvider.GetRecipes().OrderBy(i => i.Id);
            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(_recipeProvider.GetRecipes().OrderByDescending(i => i.Id).ToPagedList(pageNumber, pageSize)));
            //return View(_recipeProvider.GetRecipes().OrderBy(i => i.Id));
        }
Пример #3
0
        public ActionResult GenerateSummary()
        {
            var personalData = TempData.GetPersonalDataList();

            personalData.ForEach(pd => pd.Requirements = _requirementsProvider.GetRequirements(pd, 5));
            var bannedSubCategories  = GetBannedSubCategories();
            var bannedMainCategories = GetBannedMainCategories();

            var recipes = _recipeProvider.GetRecipes().Where(r => !bannedMainCategories.Contains(r.MainCategory) && !bannedSubCategories.Contains(r.SubCategory)).ToList();

            TempData.SavePersonalDataList(personalData);
            var nsgaSolver = _nsgaSolverFactory.GetGroupDietSolver(recipes, personalData, TempData.GetSettings().NsgaConfiguration);

            var nsgaResult = nsgaSolver.Solve();

            TempData.SaveLog(nsgaResult.Log);
            TempData.SaveNsgaResult(nsgaResult);

            var viewModelBuilder = new GroupDietViewModelBuilder();

            var dietsViewModel = viewModelBuilder.Build(nsgaResult, personalData);

            TempData.SaveGroupDietsResultViewModel(dietsViewModel);

            return(RedirectToAction("Summary"));
        }
Пример #4
0
        public ActionResult Index()
        {
            var model = _recipeProvider.GetRecipes();
            var r     = new Random();

            var rand = r.Next(0, model.Count());
            RecipesViewModel randRecipe = model./*Where(m => m.Id == 53).FirstOrDefault()*/ ElementAt(rand);
            // var c = _recipeProvider.GetRecipeProdInfo(rand).CaloricValue;
            GetRecipeProdItemInfoViewModel info = _recipeProvider.GetRecipeProdInfo(randRecipe.Id);

            ViewBag.ProdInfo = info;
            return(View(randRecipe));
        }
Пример #5
0
 public IActionResult Recipes()
 {
     return(View(_recipeProvider.GetRecipes()));
 }