Exemplo n.º 1
0
        public IActionResult Search(SearchMealInputModel inputModel, int id = 1)
        {
            if (id <= 0)
            {
                return(this.NotFound());
            }

            const int ItemsPerPage = 15;

            var result = this.mealService.GetAllSearched <MealInListViewModel>(inputModel, id);

            if (result.Count == 0)
            {
                return(this.NotFound());
            }

            var viewModel = new MealListViewModel
            {
                PageNumber      = id,
                TotalCount      = result.Count,
                Meals           = result.Meals,
                ItemsPerPage    = ItemsPerPage,
                Name            = inputModel.Name,
                CategoryId      = inputModel.CategoryId,
                SubCategory     = inputModel.SubCategory,
                SkillLevel      = inputModel.SkillLevel,
                PortionCount    = inputModel.PortionCount,
                PreparationTime = inputModel.PreparationTime,
                CookingTime     = inputModel.CookingTime,
            };

            return(this.View(viewModel));
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            var viewModel = new SearchMealInputModel();

            viewModel.CategoriesItems = this.categoriesService.GetAllCategories();

            return(this.View(viewModel));
        }
Exemplo n.º 3
0
        public void GetAllSearchedShouldReturnAllSearchedMeals()
        {
            var meals = new List <Meal>
            {
                new Meal
                {
                    Id                  = 1,
                    Name                = "TestName",
                    PreparationTime     = "10 mins",
                    CookingTime         = "10 mins",
                    SkillLevel          = SkillLevel.Easy,
                    PortionCount        = "6-8",
                    KCal                = 100,
                    Fat                 = 10,
                    Saturates           = 10,
                    Carbs               = 10,
                    Sugars              = 10,
                    Fibre               = 10,
                    Protein             = 10,
                    Salt                = 10,
                    Description         = "Some text for description",
                    MethodOfPreparation = "Some text for methodOfPreparation",
                    CategoryId          = 1,
                    SubCategoryId       = 1,
                    SubCategory         = new SubCategory {
                        Name = "Sub"
                    },
                    AddedByUserId = "userId",
                    Category      = new Category {
                        Id = 1, Name = "category"
                    },
                },
            };

            this.mealRepository.Setup(x => x.All())
            .Returns(meals
                     .AsQueryable());

            var service = new MealService(
                this.mealRepository.Object,
                this.ingredientRepository.Object,
                this.subCategoryRepository.Object);

            var inputModel = new SearchMealInputModel
            {
                Name            = "TestName",
                PortionCount    = "6-8",
                PreparationTime = "10 mins",
                CookingTime     = "10 mins",
                SkillLevel      = SkillLevel.Easy,
                SubCategory     = "Sub",
                CategoryId      = 1,
            };

            AutoMapperConfig.RegisterMappings(typeof(TestMealModel).Assembly);

            var result = service.GetAllSearched <TestMealModel>(inputModel, 1);

            Assert.Equal(1, result.Count);
            Assert.Equal("TestName", result.Meals.FirstOrDefault().Name);
            Assert.Equal("6-8", result.Meals.FirstOrDefault().PortionCount);
            Assert.Equal("10 mins", result.Meals.FirstOrDefault().PreparationTime);
            Assert.Equal("10 mins", result.Meals.FirstOrDefault().CookingTime);
            Assert.Equal(SkillLevel.Easy, result.Meals.FirstOrDefault().SkillLevel);
            Assert.Equal("Sub", result.Meals.FirstOrDefault().SubCategoryName);
            Assert.Equal(1, result.Meals.FirstOrDefault().CategoryId);
        }