コード例 #1
0
        //
        // GET: /Recipes/RecipesByCategory/1/Десерти
        public ActionResult RecipesByCategory(int?categoryID, string categoryName, int?id, bool?isPagingBtn)
        {
            int pageSize   = 8;
            int pageNumber = id.GetValueOrDefault(1);

            var    data             = this.Db.Recipes.AllRecipesByCategoryID((int)categoryID).OrderByDescending(x => x.Date).Select(AsRecipeViewModel);
            var    viewModel        = data.Skip((pageNumber - 1) * pageSize).Take(pageSize);
            double numberOfAllPages = Math.Ceiling((double)data.Count() / pageSize);

            RecipesListViewModel recipesListVM = new RecipesListViewModel()
            {
                ListTitle = "Olive-" + categoryName,
                Recipes   = viewModel,
                PageSize  = pageSize,
                RecipesListNumberOfPages = (int)numberOfAllPages,
                PagingBtnsClass          = "recipesByCategory",
                CurrentCategoryID        = (int)categoryID
            };

            if (Request.IsAjaxRequest())
            {
                Debug.WriteLine(isPagingBtn);
                if (isPagingBtn == null)
                {
                    return(PartialView("_RecipesListPartial", recipesListVM));
                }
                else
                {
                    return(PartialView("_RecipesListViewPartial", recipesListVM.Recipes));
                }
            }
            return(View("List", recipesListVM));
        }
コード例 #2
0
        public IActionResult All(int id = 1)
        {
            if (id <= 0)
            {
                return(this.NotFound());
            }

            const int ItemsPerPage = 12;
            var       viewModel    = new RecipesListViewModel()
            {
                PageNumber = id,

                // In GetAll method we give the input model which we want to visualize and present in the cshtml page
                // We can use same method but for different ViewModels because of the <T> and auto mapper functionality
                Recipes      = this.recipesService.GetAll <RecipeInListVIewModel>(id, 12),
                RecipesCount = this.recipesService.GetCount(),
                ItemsPerPage = ItemsPerPage,
            };

            if (id > viewModel.PagesCount)
            {
                return(this.NotFound());
            }

            return(this.View(viewModel));
        }
コード例 #3
0
        public ActionResult Search(string searchString, int?id)
        {
            int pageSize   = 8;
            int pageNumber = id.GetValueOrDefault(1);

            var    viewModel        = GetAllSearchRecipes(searchString).Skip((pageNumber - 1) * pageSize).Take(pageSize);
            double numberOfAllPages = Math.Ceiling((double)GetAllSearchRecipes(searchString).Count() / pageSize);

            RecipesListViewModel recipesListVM = new RecipesListViewModel()
            {
                ListTitle = "Olive-Резултати от търсене за: " + searchString,
                Recipes   = viewModel,
                PageSize  = pageSize,
                RecipesListNumberOfPages = (int)numberOfAllPages,
                PagingBtnsClass          = "searchRecipesList"
            };

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_RecipesListViewPartial", recipesListVM.Recipes));
            }
            else
            {
                if (String.IsNullOrEmpty(searchString))
                {
                    return(RedirectToAction("List"));
                }
                return(View(recipesListVM));
            }
        }
コード例 #4
0
        public ViewResult List(string category, string searchValue = "", int page = 1)
        {
            if (searchValue != null)
            {
                @ViewBag.SearchValue = searchValue;
            }

            RecipesListViewModel model = new RecipesListViewModel
            {
                Recipes = repository.Recipes
                          .Where(p => (category == null || p.Category == category) && (String.IsNullOrEmpty(searchValue)?true:((p.Name.Contains(searchValue) || p.Ingredients.Any(c => c.Name.Contains(searchValue))))))
                          .OrderBy(recipe => recipe.RecipeID)
                          .Skip((page - 1) * pageSize)
                          .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = 0
                },

                CurrentCategory = category
            };

            model.PagingInfo.TotalItems = repository.Recipes.Count(p => (category == null || p.Category == category) &&
                                                                   (String.IsNullOrEmpty(searchValue) || ((p.Name.Contains(searchValue) || p.Ingredients.Any(c => c.Name.Contains(searchValue))))));
            return(View(model));
        }
コード例 #5
0
        //
        // GET: /Recipes/List/2
        public ActionResult List(int?id, bool?isPagingBtn)
        {
            int pageSize   = 8;
            int pageNumber = id.GetValueOrDefault(1);

            var    viewModel        = GetAllRecipes().Skip((pageNumber - 1) * pageSize).Take(pageSize);
            double numberOfAllPages = Math.Ceiling((double)GetAllRecipes().Count() / pageSize);

            RecipesListViewModel recipesListVM = new RecipesListViewModel()
            {
                ListTitle = "Olive-Всички рецепти",
                Recipes   = viewModel,
                PageSize  = pageSize,
                RecipesListNumberOfPages = (int)numberOfAllPages,
                PagingBtnsClass          = "allRecipesList"
            };

            if (Request.IsAjaxRequest())
            {
                Debug.WriteLine(isPagingBtn);
                if (isPagingBtn == null)
                {
                    return(PartialView("_RecipesListPartial", recipesListVM));
                }
                else
                {
                    return(PartialView("_RecipesListViewPartial", recipesListVM.Recipes));
                }
            }
            return(View(recipesListVM));
        }
コード例 #6
0
        public RecipesListViewModelTests()
        {
            this.recipeRepositoryMock = new Mock <IRecipeRepository>();
            this.mediatorMock         = new Mock <Mediator>()
            {
                CallBase = true
            };

            recipeRepositoryMock.Setup(repository => repository.GetAll())
            .Returns(() => new List <RecipeListModel>());

            this.recipesListViewModelSUT = new RecipesListViewModel(recipeRepositoryMock.Object, mediatorMock.Object);
        }
コード例 #7
0
        public IActionResult All(int id = 1)
        {
            const int ItemsPerPage = 15;
            var       viewModel    = new RecipesListViewModel
            {
                ItemsPerPage = ItemsPerPage,
                PageNumber   = id,
                RecipesCount = this.recipesService.GetCount(),
                Recipes      = this.recipesService.GetAll <RecipeInListViewModel>(id, ItemsPerPage),
            };

            return(this.View(viewModel));
        }
コード例 #8
0
        public IActionResult All(int id = 1)
        {
            if (id <= 0)
            {
                return(this.NotFound());
            }

            const int ItemsPerPage = 12;
            var       viewModel    = new RecipesListViewModel()
            {
                ItemsPerPage = ItemsPerPage,
                PageNumber   = id,
                RecipesCount = this.recipeService.GetCount(),
                Recipes      = this.recipeService.GetAll <RecipeInListViewModel>(id, ItemsPerPage),
            };

            return(this.View(viewModel));
        }
コード例 #9
0
        public IActionResult All(int id = 1)
        {
            const int itemsPerPage = 12;
            var       viewModel    = new RecipesListViewModel
            {
                ItemsPerPage = itemsPerPage,
                PageNumber   = id,
                Recipes      = this.recipesService.GetAll <RecipeInListViewModel>(id, itemsPerPage),
                RecipesCount = this.recipesService.GetCount(),
            };

            if (id <= 0 || id > viewModel.PagesCount)
            {
                return(this.NotFound());
            }

            return(this.View(viewModel));
        }
コード例 #10
0
        public IActionResult All(int id = 1) // За пейджирането. Това ще бъде номера на страницата.
        {
            if (id < 1)
            {
                return(this.NotFound());
            }

            const int ItemsPerPage = 12;

            var viewModel = new RecipesListViewModel
            {
                ItemsPerPage = ItemsPerPage,
                PageNumber   = id,
                RecipesCount = this.recipeService.GetCount(),
                Recipes      = this.recipeService.GetAll <RecipeInListViewModel>(id, ItemsPerPage),
            };

            return(this.View(viewModel));
        }
コード例 #11
0
        public ActionResult Search(RecipesListViewModel recipeListVM)
        {
            var list
                = (_repo.GetRecipes())
                  .ProjectTo <RecipeViewModel>()
                  .Where(r => r.isPublic).ToList();

            if (recipeListVM.CurrentMealTypeID != 0)
            {
                list = (from l in list
                        where l.MealTypeId == recipeListVM.CurrentMealTypeID
                        select l).ToList();
            }

            if (!string.IsNullOrEmpty(recipeListVM.SearchName))
            {
                list = list.Where(r => r.Name.Contains(recipeListVM.SearchName)).ToList();
            }
            recipeListVM.Recipes = list;
            return(View(recipeListVM));
        }
コード例 #12
0
        public ViewResult SearchList(string search, int recipePage = 1)
        {
            RecipesListViewModel list = new RecipesListViewModel
            {
                Recipes = repository.Recipes
                          .Where(p => p.Name.Contains(search))
                          .Skip((recipePage - 1) * PageSize)
                          .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage    = recipePage,
                    RecipesPerPage = PageSize,
                    TotalRecipes   = repository.Recipes.Count()
                }
            };

            if (list.Recipes.Count() == 0)
            {
                ViewBag.Message = "No recipes found!";
            }

            return(View("List", list));
        }
コード例 #13
0
        public async Task <ActionResult> Index(int?page = 1)
        {
            var client = sRecipeHttpClient.GetClient();
            var model  = new RecipesListViewModel();
            HttpResponseMessage response = await client.GetAsync("api/recipes");

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                var pagingInfo = HeaderParser.FindAndParsePagingInfo(response.Headers);
                var lstRecipes = JsonConvert.DeserializeObject <IEnumerable <Recipe> >(content);
                var pagedList  = new StaticPagedList <Recipe>(lstRecipes, pagingInfo.CurrentPage,
                                                              pagingInfo.PageSize, pagingInfo.TotalCount
                                                              );
                model.Recipes    = pagedList;
                model.PagingInfo = pagingInfo;
            }
            else
            {
                return(Content("An error ocurred."));
            }
            return(View(model));
        }
コード例 #14
0
        public ActionResult EditRecipe(RecipesListViewModel recipesListViewModel)
        {
            recipesListViewModel.Recipe.DateTimeUpdate = DateTime.Now;

            /**
             * Console.WriteLine("recipe IngredientString = " + recipesListViewModel.IngredientString);
             *
             *
             * Console.WriteLine("rlview recipeId = " + recipesListViewModel.Recipe.RecipeId);
             * Console.WriteLine("rlview RecipeTitle = " + recipesListViewModel.Recipe.RecipeTitle);
             * Console.WriteLine("rlview CategoryId = " + recipesListViewModel.Recipe.CategoryId);
             *
             *
             * Console.WriteLine("rlview Description = " + recipesListViewModel.Recipe.Description);
             *
             * Console.WriteLine("rlview Servings = " + recipesListViewModel.Recipe.Servings);
             * Console.WriteLine("rlview ServingsMax = " + recipesListViewModel.Recipe.ServingsMax);
             * Console.WriteLine("rlview Total = " + recipesListViewModel.Recipe.Total);
             * Console.WriteLine("rlview Yield = " + recipesListViewModel.Recipe.Yield);
             * Console.WriteLine("rlview CookTime = " + recipesListViewModel.Recipe.CookTime);
             * Console.WriteLine("rlview Prep = " + recipesListViewModel.Recipe.Prep);
             * Console.WriteLine("rlview DateTimeUpdate = " + recipesListViewModel.Recipe.DateTimeUpdate);
             * //string strName = Request.Form["pair.Value"].ToString();
             * //Console.WriteLine("pair.value = " + strName);
             */



            if (ModelState.IsValid)
            {
                recipesListViewModel.Recipe.FileToUpload = getFileUrlName();
                Console.WriteLine("rlview FileToUpload = " + recipesListViewModel.Recipe.FileToUpload);

                //Insert new recipe in recipe table
                iRecipeRepo.UpdateRecipe(recipesListViewModel.Recipe);


                foreach (ChangedIngredientDetail chnIngredientDetail in recipesListViewModel.ChangedIngredientDetails)
                {
                    //Console.WriteLine("ingredientString value of UpdateIngredientDetail in EditRecipe() = " + chnIngredientDetail.IngredientString);
                    if (string.IsNullOrEmpty(chnIngredientDetail.IngredientString))
                    {
                        Console.WriteLine("There is a empty or null in the ingredient detail by the user input (ingredientString is null) in the recipe Id ["
                                          + recipesListViewModel.Recipe.RecipeId + "]");
                    }
                    else
                    {
                        IngredientDetail updateingredientDetail = new IngredientDetail();

                        updateingredientDetail.IngredientId     = chnIngredientDetail.IngredientId;
                        updateingredientDetail.IngredientString = chnIngredientDetail.IngredientString;

                        Console.WriteLine("ingredientString value in EditRecipe() = " + updateingredientDetail.IngredientId);
                        Console.WriteLine("ingredientString value in EditRecipe() = " + updateingredientDetail.IngredientString);

                        iIngredientDetailRepo.UpdateIngredientDetail(updateingredientDetail);
                    }
                }

                return(RedirectToAction("List", "Data"));
            }
            else
            {
                return(View("RecipeList", rlv));
            }
        }