public async Task <IActionResult> OnGetAsync(string toggleId = null) { if (!string.IsNullOrEmpty(toggleId)) { Tags = AllergyTagHelper.LoadTags(HttpContext.Session); var tag = Tags.FirstOrDefault(t => t.Value == toggleId); tag.Selected = !tag.Selected; AllergyTagHelper.SaveTags(HttpContext.Session, Tags); return(RedirectToPage("./Categories", new { CategoryId = CategoryId })); } Categories = await _ds.GetProductCategoriesAsync(); Tags = AllergyTagHelper.LoadTags(HttpContext.Session); if (Tags == null) { Tags = await _ds.GetTagsListAsync(); AllergyTagHelper.SaveTags(HttpContext.Session, Tags); } if (CategoryId != null) { Products = await _ds.GetProductsByCategoryAsync(CategoryId.Value); CategoryName = Categories.FirstOrDefault(c => c.Id == CategoryId).Name; if (CategoryName == "Färdiga paket") { Products = Products.OrderBy(o => o.Price); } } else { var list = await _ds.GetProductsAsync(); Products = list.Where(c => c.Category.Name != "Färdiga paket").OrderBy(o => o.Name); } MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session); if (CategoryName != "Färdiga paket") { Products = _ds.FilteredProducts(Products, Tags); } ViewData["MainLayout"] = MainLayout; return(Page()); }
public async Task <IActionResult> OnGetAsync(string toggleId = null) { if (!string.IsNullOrEmpty(toggleId)) { Tags = AllergyTagHelper.LoadTags(HttpContext.Session); var tag = Tags.FirstOrDefault(t => t.Value == toggleId); tag.Selected = !tag.Selected; AllergyTagHelper.SaveTags(HttpContext.Session, Tags); return(RedirectToPage("./Search", new { Query = Query })); } Tags = AllergyTagHelper.LoadTags(HttpContext.Session); if (Tags == null) { Tags = await _ds.GetTagsListAsync(); AllergyTagHelper.SaveTags(HttpContext.Session, Tags); } var products = await _ds.GetProductsAsync(); if (!String.IsNullOrEmpty(Query)) { SearchResults = products.Where(p => p.Name.ToUpper().Contains(Query.ToUpper()) && p.Category.Name != "Färdiga paket").ToList(); if (SearchResults.Count() > 0) { SearchResults = _ds.FilteredProducts(SearchResults, Tags); } } MainLayout.ShoppingBasket = BasketHelper.GetBasket(HttpContext.Session); ViewData["MainLayout"] = MainLayout; return(Page()); }