Example #1
0
        public async Task <IActionResult> OnGetAsync()
        {
            GetSessionValues();
            RecipeHeaders = (await recipeRepository.GetRecipeHeaders()).Where(x => x.RecipeType == Common.Enumeration.RecipeType.Done);
            RecipeImages  = (await recipeImageRepository.GetRecipeImages()).Where(x => x.ProfileImage);

            if (IsUserLogged() && CurrentUser != null)
            {
                UserFavoriteRecipes = await userFavoriteRecipeRepository.GetUserFavoriteRecipes(CurrentUser.Id);
            }

            if (UserRecipeOrderBy == UserRecipeOrderBy.Ascending)
            {
                RecipeHeaders = RecipeHeaders.OrderBy(x => x.Name);
            }
            else if (UserRecipeOrderBy == UserRecipeOrderBy.Descending)
            {
                RecipeHeaders = RecipeHeaders.OrderByDescending(x => x.Name);
            }
            else if (UserRecipeOrderBy == UserRecipeOrderBy.Favorite)
            {
                var favoriteRecipes = new List <RecipeHeader>();
                foreach (var recipeHeader in RecipeHeaders)
                {
                    if (UserFavoriteRecipes.Any(x => x.RecipeHeaderId == recipeHeader.Id))
                    {
                        favoriteRecipes.Add(recipeHeader);
                    }
                }

                RecipeHeaders = favoriteRecipes.AsEnumerable().OrderBy(x => x.Name);
            }

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int?draftHeaderId)
        {
            if (!CheckPermissions())
            {
                return(RedirectToPage(Url.Content("~/Home/Index")));
            }

            if (draftHeaderId.HasValue)
            {
                RecipeHeader = await recipeRepository.GetRecipeHeader(draftHeaderId.Value);

                RecipeDetails = await recipeRepository.GetRecipeDetails(RecipeHeader.Id);

                DraftRecipeHeaderId = draftHeaderId.Value;
            }

            if (RecipeHeader is null)
            {
                RecipeHeader = new RecipeHeader
                {
                    RecipeType = SmartCooking.Common.Enumeration.RecipeType.Draft
                };
                await recipeRepository.InsertRecipeHeader(RecipeHeader);

                return(RedirectToPage("RecipeCreate", new { draftHeaderId = RecipeHeader.Id }));
            }

            RecipeImages = await recipeImageRepository.GetRecipeImages(draftHeaderId.Value);

            return(Page());
        }
Example #3
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!IsUserLogged())
            {
                RedirectToPage(Url.Content($"~/Home/Index"));
            }

            this.UserFavoriteRecipes = await userFavoriteRecipeRepository.GetUserFavoriteRecipes(CurrentUser.Id);

            this.RecipeHeaders = await recipeRepository.GetRecipeHeaders();

            this.RecipeImages = await recipeImageRepository.GetRecipeImages();

            return(Page());
        }
Example #4
0
        public async Task <IActionResult> OnGetAsync(int?recipeId)
        {
            GetSessionValues();
            if (!recipeId.HasValue)
            {
                return(RedirectToPage(Url.Content($"~/Home/Index")));
            }

            RecipeHeader = await recipeRepository.GetRecipeHeader(recipeId.Value);

            if (RecipeHeader is null)
            {
                return(RedirectToPage(Url.Content($"~/Home/Index")));
            }

            RecipeDetails = await recipeRepository.GetRecipeDetails(recipeId.Value);

            RecipeImages = await recipeImageRepository.GetRecipeImages(recipeId.Value);

            ViewData["Title"] = RecipeHeader.Name;
            return(Page());
        }
        public async Task <IActionResult> OnGetAsync()
        {
            List <string> ingredients = IngredientsText.Split("-", StringSplitOptions.RemoveEmptyEntries).ToList();

            var dbItems = await itemRepository.GetItems();

            // Διαγραφή όποιων υλικών δεν υπάρχουν
            for (int i = ingredients.Count - 1; i >= 0; i--)
            {
                if (!dbItems.Any(itm => itm.Name == ingredients[i]))
                {
                    ingredients.Remove(ingredients[i]);
                }
            }

            List <Item> items = new List <Item>();

            foreach (var ingredient in ingredients)
            {
                items.Add(await itemRepository.GetItem(ingredient));
            }

            List <RecipeHeader> recipeHeaders = new List <RecipeHeader>();
            var dbRecipeDetails = await recipeRepository.GetRecipeDetails();

            foreach (var item in items)
            {
                var tempRecipeDetails = dbRecipeDetails.Where(x => x.ItemId == item.Id);

                foreach (var tempRecipeDetail in tempRecipeDetails)
                {
                    if (tempRecipeDetail.RecipeHeaderId.HasValue)
                    {
                        recipeHeaders.Add(await recipeRepository.GetRecipeHeader(tempRecipeDetail.RecipeHeaderId.Value));
                    }
                }
            }

            var recipeCountViewModel = new RecipeCountViewModel();

            recipeCountViewModel.RecipeHeaders      = recipeHeaders.Distinct();
            recipeCountViewModel.RecipeHeaderCounts = recipeHeaders
                                                      .GroupBy(g => g.Id)
                                                      .Select(x => new RecipeHeaderCount()
            {
                Key = x.Key, Count = x.Count()
            });

            RecipeCountViewModel = recipeCountViewModel;

            foreach (var recipeHeader in RecipeCountViewModel.RecipeHeaders)
            {
                var img = (await recipeImageRepository.GetRecipeImages(recipeHeader.Id))?.FirstOrDefault(x => x.ProfileImage);
                if (img != null)
                {
                    if (RecipeImages is null)
                    {
                        RecipeImages = new List <RecipeImage>();
                    }

                    RecipeImages.Add(img);
                }
            }

            return(Page());
        }