예제 #1
0
        public async Task <IActionResult> CreateBasicFilters()
        {
            var categories = await this.productsServices.GetAllCategoryNamesAsync();

            var model = new InsertBasicFiltersViewModel
            {
                Categories = categories.ToList()
            };

            return(View(model));
        }
예제 #2
0
        public async Task TestIfBasicFiltersExistForCategoryReturnsTrue(string categoryName)
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var filtersService = new Areas.Administration.Services.AdminFiltersServices(context);

            var form = new InsertBasicFiltersViewModel();

            form.Category = categoryName;

            await filtersService.CreateBasicFiltersAsync(form);

            Assert.True(await filtersService.BasicFiltersExistForCategoryAsync(categoryName));
        }
예제 #3
0
        public async Task CreateBasicFiltersAsync(InsertBasicFiltersViewModel form)
        {
            await this.context.FilterCategories.AddAsync(new FilterCategory
            {
                CategoryName        = form.Category,
                ViewSubCategoryName = "Order By",
                Filters             = new List <PCHUBStore.Data.Models.Filter>
                {
                    new PCHUBStore.Data.Models.Filter
                    {
                        Name  = "Price Ascending",
                        Value = "PriceAsc"
                    },
                    new PCHUBStore.Data.Models.Filter
                    {
                        Name  = "Price Descending",
                        Value = "PriceDesc"
                    },
                    new PCHUBStore.Data.Models.Filter
                    {
                        Name  = "Default",
                        Value = "Default",
                    },
                }
            });

            await this.context.FilterCategories.AddAsync(new FilterCategory
            {
                CategoryName        = form.Category,
                ViewSubCategoryName = "Price",
                Filters             = new List <PCHUBStore.Data.Models.Filter>
                {
                    new PCHUBStore.Data.Models.Filter
                    {
                        Name  = "MinPrice",
                        Value = "0"
                    },
                    new PCHUBStore.Data.Models.Filter
                    {
                        Name  = "MaxPrice",
                        Value = "9999"
                    },
                }
            });

            await this.context.SaveChangesAsync();
        }
예제 #4
0
        public async Task TestIfCreateBasicFiltersWorksAccordingly(string categoryName)
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var filtersService = new Areas.Administration.Services.AdminFiltersServices(context);

            var form = new InsertBasicFiltersViewModel();

            form.Category = categoryName;

            await filtersService.CreateBasicFiltersAsync(form);

            var result = await context.FilterCategories.FirstOrDefaultAsync(x => x.CategoryName == categoryName);

            Assert.NotNull(result);

            Assert.Contains(result.Filters, x => x.Value != null);
        }
예제 #5
0
        public async Task <IActionResult> CreateBasicFilters(InsertBasicFiltersViewModel filterCategory)
        {
            var categories = await this.productsServices.GetAllCategoryNamesAsync();

            filterCategory.Categories = categories.ToList();
            if (!categories.Any(x => x == filterCategory.Category))
            {
                this.ModelState.AddModelError("Product", "Category Product doesnt exist");
            }

            if (await this.service.BasicFiltersExistForCategoryAsync(filterCategory.Category))
            {
                this.ModelState.AddModelError("Filters", "Basic filters already created for this category");
            }

            if (ModelState.IsValid)
            {
                await this.service.CreateBasicFiltersAsync(filterCategory);

                return(this.RedirectToAction("Success", "Blacksmith", new { message = $"Successfully created Basic filters for: {filterCategory.Category}" }));
            }

            return(View(filterCategory));
        }