Пример #1
0
        public RecipeOverviewViewModel LoadRecipeOverview(int count, int skip, string category, string subCategory, bool isFriend)
        {
            string headline = "Top Rezepte";

            if (!String.IsNullOrEmpty(subCategory))
            {
                headline = "Rezepte zum Thema " + _categoryRespository.LoadSubCategoryNameByUrl(subCategory);
            }
            else if (!String.IsNullOrEmpty(category))
            {
                headline = "Rezepte zum Thema " + _categoryRespository.LoadCategoryNameByUrl(category);
            }
            RequestRecipe request = new RequestRecipe()
            {
                Top            = count,
                ForPublicWeb   = true,
                IsFriend       = isFriend,
                CategoryUrl    = category,
                SubCategoryUrl = subCategory
            };
            int recipeCount = _recipeRepository.LoadOverviewRecipesCount(request);

            request.Skip = skip;

            List <IRecipeOverviewData> recipes = _recipeRepository.LoadOverviewRecipes(request);

            return(MapRecipeOverviewViewModel(recipes, recipeCount, headline));
        }
Пример #2
0
        public SearchResultViewModel SearchRecipes(string term, bool isFriend)
        {
            int           recipesPerPage = 8;
            RequestRecipe request        = new RequestRecipe()
            {
                Top          = recipesPerPage,
                ForPublicWeb = true,
                IsFriend     = isFriend,
                SearchTerm   = term
            };

            List <IRecipeOverviewData> recipes = _recipeRepository.LoadOverviewRecipes(request);

            if (recipes == null)
            {
                return(null);
            }
            SearchResultViewModel model = new SearchResultViewModel()
            {
                SearchTerm = term
            };

            foreach (IRecipeOverviewData recipe in recipes)
            {
                model.Recipes.Add(new SearchResultRecipeViewModel()
                {
                    Id             = recipe.Id,
                    Name           = recipe.Name,
                    TeaserImageUrl = String.IsNullOrEmpty(recipe.TeaserImageUrl) ? "default_teaser_image.png" : recipe.TeaserImageUrl,
                    Url            = recipe.Url
                });
            }
            return(model);
        }
Пример #3
0
        public RecipeOverviewViewModel LoadRecipesFromSubCategories(int page, bool isFriend, string url)
        {
            int           recipesPerPage = 10;
            RequestRecipe request        = new RequestRecipe()
            {
                Top            = recipesPerPage,
                ForPublicWeb   = true,
                IsFriend       = isFriend,
                SubCategoryUrl = url
            };

            int recipeCount = _recipeRepository.LoadOverviewRecipesCount(request);
            int maxPages    = (int)(recipeCount / recipesPerPage);

            if (maxPages < ((decimal)recipeCount / (decimal)recipesPerPage))
            {
                maxPages = maxPages + 1;
            }

            if (page > maxPages)
            {
                page = maxPages;
            }
            request.Skip = (recipesPerPage * page) - recipesPerPage;
            if ((recipeCount - request.Skip) < request.Top)
            {
                request.Top = (recipeCount - request.Skip);
            }

            List <IRecipeOverviewData> recipes = _recipeRepository.LoadOverviewRecipes(request);
            string name = _categoryRespository.LoadSubCategoryNameByUrl(url);

            return(MapRecipeOverviewViewModel(recipes, recipeCount, "Rezepte zum Thema " + name));
        }
Пример #4
0
        public RecipeOverviewViewModel LoadCMSRecipes(int count, int skip)
        {
            RequestRecipe request = new RequestRecipe()
            {
                Top          = count,
                Skip         = skip,
                ForPublicWeb = false,
                IsFriend     = true
            };
            int recipeCount = _recipeRepository.LoadOverviewRecipesCount(request);
            List <IRecipeOverviewData> recipes = _recipeRepository.LoadOverviewRecipes(request);

            return(MapRecipeOverviewViewModel(recipes, recipeCount, "Rezept Übersicht"));
        }