public async Task <IActionResult> CreateBasicFilters() { var categories = await this.productsServices.GetAllCategoryNamesAsync(); var model = new InsertBasicFiltersViewModel { Categories = categories.ToList() }; return(View(model)); }
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)); }
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(); }
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); }
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)); }