public DiscountListView() { InitializeComponent(); discountListViewModel = new DiscountListViewModel(Navigation); BindingContext = discountListViewModel; }
public ActionResult DiscountList(string vCity, string vZip, ShoppingCart cart, BrowseHistory bh) { DiscountListViewModel dlv = new DiscountListViewModel(); dlv.History = bh; dlv.LBizInfos = BizInfoRepository.GetBizInfosByCityZip(vCity, vZip).Where(e => e.HasDiscountCoupons || e.HasFreeItemCoupons).ToList(); ViewBag.bagitems = GetCartItems(cart); return(View(dlv)); }
/// <summary> /// 优惠列表查询 /// </summary> public ActionResult DiscountList(DiscountListSearchModel search) { DiscountListViewModel model = new DiscountListViewModel(); //页面模型 model.search = search; //页面的搜索模型 model.search.PageSize = 15; //每页显示 model.search.CurrentPage = Convert.ToInt32(Request["pageindex"]) <= 0 ? 1 : Convert.ToInt32(Request["pageindex"]); //当前页 //按钮下拉项 List <CommonEntity> SourceIL = CommonData.GetDictionaryList(15); //1是字典类型值,仅供测试参考 model.SourceIL = CommonData.Instance.GetBropDownListData(SourceIL); model.Discountlist = DiscountData.GetDiscountList(search); //填充页面模型数据 return(View(model)); //返回页面模型 }
public async Task <IActionResult> Index(bool isSearch = false, string searchText = "", int?categoryId = null, bool backToParentCategory = false, string absoluteNavigationPath = null, string navigateToCategoryNamed = null) { ViewBag.CurrentPageNumber = startingPageNumber; ViewBag.PreviousPageNumber = null; ViewBag.NextPageNumber = 1; ViewBag.SearchText = searchText; //Used for search pagination :( ViewBag.IsSearch = isSearch; //Used for search pagination :( Category currentCategory = null; ICollection <Product> productsToView = null; // products to return in current page ICollection <Product> filteredProducts = null; //Used for search if (isSearch) { filteredProducts = await _productService.SearchForProducts(searchText); } ICollection <Category> selectableCategories = null;// navigation menu if (categoryId == null) { if (navigateToCategoryNamed == null)// (GET) { // build menu selectableCategories = await _navigationService.GetTopLevelCategoriesAsync(); //ViewBag.ParentCategoryId = null; //ViewBag.AbsoluteNavigationPath = null; ViewBag.CurrentCategoryId = categoryId; if (!isSearch) { productsToView = await _navigationService.GetProductsInCategoryByPageAsync(null, startingPageNumber, productsPerPage); } else { productsToView = filteredProducts.Skip(startingPageNumber * productsPerPage).Take(productsPerPage).ToList(); } } else// (POST) specific path segment selected ([segment]/.../...) { // get that category by name currentCategory = await _navigationService.GetCategoryByName(navigateToCategoryNamed); // build menu selectableCategories = await _navigationService.GetChildCategoriesAsync(currentCategory); // products to return productsToView = await _navigationService.GetProductsInCategoryByPageAsync(currentCategory, startingPageNumber, productsPerPage); // get parent category by absoluteNavigationPath string[] pathSegments = absoluteNavigationPath.Split("/"); pathSegments = pathSegments.Skip(1).ToArray();// remove empty segment ([empty segment]/[some segment]/...) int parentCategoryIndexInPath = Array.IndexOf(pathSegments, navigateToCategoryNamed); string newAbsoluteNavigationPath = null; string parentCategoryName = null; await Task.Run(() => { for (int i = 0; i < pathSegments.Count(); i++) { if (i == parentCategoryIndexInPath) { parentCategoryName = pathSegments[i]; } if (i <= parentCategoryIndexInPath) { newAbsoluteNavigationPath += ("/" + pathSegments[i]); } } }); Category parentCategory = await _navigationService.GetCategoryByName(parentCategoryName); ViewBag.ParentCategoryId = parentCategory.Id; ViewBag.AbsoluteNavigationPath = newAbsoluteNavigationPath; ViewBag.CurrentCategoryName = parentCategory.Name; ViewBag.CurrentCategoryId = currentCategory.Id; } } else// (POST) backward and forward navigation { currentCategory = await _navigationService.GetCategoryById(categoryId); if (backToParentCategory)// Backward navigation { absoluteNavigationPath = await _navigationService.RemoveLastUriSegmentAsync(absoluteNavigationPath); ViewBag.AbsoluteNavigationPath = absoluteNavigationPath; selectableCategories = null;// navigation menu Category parentCategory = null; // categories may have multiple parent-categories ICollection <Category> parentCategories = await _navigationService.GetParentCategoriesAsync(currentCategory); if (!parentCategories.Any())// already a top-level category { selectableCategories = await _navigationService.GetTopLevelCategoriesAsync(); ViewBag.ParentCategoryId = null; ViewBag.CurrentCategoryId = currentCategory.Id; ViewBag.AbsoluteNavigationPath = null; ViewBag.CurrentCategoryName = null; productsToView = await _navigationService.GetProductsInCategoryByPageAsync(null, startingPageNumber, productsPerPage); // for later page count calculation currentCategory = null; } else// not a top-level category { foreach (Category pCategory in parentCategories) { // search for parent-category based on absoluteNavigationPath last segment if (pCategory.Name.Equals(absoluteNavigationPath.Split('/').Last())) { parentCategory = pCategory; break; } } // build menu selectableCategories = await _navigationService.GetChildCategoriesAsync(parentCategory); ViewBag.CurrentCategoryName = parentCategory.Name; ViewBag.ParentCategoryId = parentCategory.Id; ViewBag.CurrentCategoryId = parentCategory.Id; // products to return productsToView = await _navigationService.GetProductsInCategoryByPageAsync(parentCategory, startingPageNumber, productsPerPage); // for later page count calculation currentCategory = parentCategory; } } else // Forward navigation { // Add new segment to absoluteNavigationPath absoluteNavigationPath += ("/" + currentCategory.Name); ViewBag.AbsoluteNavigationPath = absoluteNavigationPath; // build menu selectableCategories = selectableCategories = await _navigationService.GetChildCategoriesAsync(currentCategory); ViewBag.CurrentCategoryName = currentCategory.Name; ViewBag.ParentCategoryId = categoryId; ViewBag.CurrentCategoryId = currentCategory.Id; // products to return if (categoryId == null) { productsToView = await _navigationService.GetProductsInCategoryByPageAsync(null, startingPageNumber, productsPerPage); } else { productsToView = await _navigationService.GetProductsInCategoryByPageAsync(currentCategory, startingPageNumber, productsPerPage); } } } int pageCount = 0; if (!isSearch) { pageCount = await _navigationService.GetProductsInCategoryPageCount(currentCategory, productsPerPage); } else //If search { pageCount = filteredProducts.Count / productsPerPage; if (filteredProducts.Count % productsPerPage != 0) { pageCount++; } } ViewBag.PageCount = pageCount; if (startingPageNumber + 1 < pageCount) { ViewBag.NextPageNumber = startingPageNumber + 1; } else { ViewBag.NextPageNumber = null; } ViewBag.TopLevelCategories = selectableCategories; String[] allPrimaryImageLinks = await _productService.GetAllImages(productsToView); ViewBag.AllPrimaryImageLinks = allPrimaryImageLinks; // ----------------------------------------- ICollection <ProductAd> productAds = await _productService.GetProductAds(); ViewBag.ProductAds = productAds; //------- discountai ------------// DiscountListViewModel dlvm = await GetDiscountList(productsToView); ViewBag.HasDiscountList = dlvm.HasDiscountList; ViewBag.DiscountPriceList = dlvm.DiscountPriceList; ViewBag.DiscountEndDateList = dlvm.DiscountEndDateList; //------- atributai ------------// AttributeListViewModel alvm = await GetAttributeListInCategory(currentCategory); ViewBag.AttributeValues = alvm.AttributeValues; ViewBag.Attributes = alvm.Attributes; return(View(productsToView)); }
public async Task <IActionResult> FilterByAttributes(bool isSearch, string searchText, string attributeName, int pageCount, int?categoryId = null, int?parentCategoryId = null, ICollection <Category> topLevelCategories = null, string absoluteNavigationPath = null, int pageNumber = startingPageNumber) { ViewBag.ParentCategoryId = parentCategoryId; ViewBag.AbsoluteNavigationPath = absoluteNavigationPath; ViewBag.CurrentCategoryId = categoryId; ViewBag.CurrentPageNumber = pageNumber; ViewBag.IsSearch = isSearch; //Used for search pagination ViewBag.SearchText = searchText; //Used for search pagination Category category = null; if (parentCategoryId != null) { category = await _navigationService.GetCategoryById(parentCategoryId); } pageCount = await _navigationService.GetProductsInCategoryPageCount(category, productsPerPage, attributeName); ViewBag.PageCount = pageCount; if (pageNumber + 1 < pageCount) { ViewBag.NextPageNumber = pageNumber + 1; } else { ViewBag.NextPageNumber = null; } if (pageNumber > 0) { ViewBag.PreviousPageNumber = pageNumber - 1; } else { ViewBag.PreviousPageNumber = null; } if (category == null) { ViewBag.TopLevelCategories = await _navigationService.GetTopLevelCategoriesAsync(); ViewBag.CurrentCategoryName = null; ViewBag.AbsoluteNavigationPath = null; } else { ViewBag.TopLevelCategories = await _navigationService.GetChildCategoriesAsync(category); ViewBag.CurrentCategoryName = category.Name; } ICollection <Product> products = await _navigationService.GetProductsInCategoryByPageAsync(category, pageNumber, productsPerPage, attributeName); var listProducts = products.ToList(); //--------- images --------------// ViewBag.AllPrimaryImageLinks = await GetProductImages(listProducts); //---------- ads ----------------// ICollection <ProductAd> productAds = await _productService.GetProductAds(); ViewBag.ProductAds = productAds; //------- discountai ------------// DiscountListViewModel dlvm = await GetDiscountList(listProducts); ViewBag.HasDiscountList = dlvm.HasDiscountList; ViewBag.DiscountPriceList = dlvm.DiscountPriceList; ViewBag.DiscountEndDateList = dlvm.DiscountEndDateList; //------- atributai ------------// AttributeListViewModel alvm = await GetAttributeListInCategory(category); ViewBag.AttributeValues = alvm.AttributeValues; ViewBag.Attributes = alvm.Attributes; ViewBag.SelectedAttributeValueName = attributeName; return(View("Index", products)); }
public async Task <IActionResult> LoadPage(string attributeName, bool isSearch, string searchText, /* redundant --> */ int pageCount, int?categoryId = null, int?parentCategoryId = null, ICollection <Category> topLevelCategories = null, string absoluteNavigationPath = null, int pageNumber = startingPageNumber) { ViewBag.ParentCategoryId = parentCategoryId; ViewBag.AbsoluteNavigationPath = absoluteNavigationPath; ViewBag.CurrentCategoryId = categoryId; ViewBag.CurrentPageNumber = pageNumber; ViewBag.PageCount = pageCount; ViewBag.IsSearch = isSearch; //Used for search pagination ViewBag.SearchText = searchText; //Used for search pagination if (pageNumber + 1 < pageCount) { ViewBag.NextPageNumber = pageNumber + 1; } else { ViewBag.NextPageNumber = null; } if (pageNumber > 0) { ViewBag.PreviousPageNumber = pageNumber - 1; } else { ViewBag.PreviousPageNumber = null; } Category category = null; if (parentCategoryId != null) { category = await _navigationService.GetCategoryById(parentCategoryId); } ICollection <Product> products = new List <Product>(); if (!isSearch) { if (category == null) { ViewBag.TopLevelCategories = await _navigationService.GetTopLevelCategoriesAsync(); ViewBag.CurrentCategoryName = null; ViewBag.AbsoluteNavigationPath = null; } else { ViewBag.TopLevelCategories = await _navigationService.GetChildCategoriesAsync(category); ViewBag.CurrentCategoryName = category.Name; } products = await _navigationService.GetProductsInCategoryByPageAsync(category, pageNumber, productsPerPage); } else //If it's search state { //To prevent null reference ViewBag.TopLevelCategories = await _navigationService.GetTopLevelCategoriesAsync(); ViewBag.CurrentCategoryName = null; ViewBag.AbsoluteNavigationPath = null; products = await _productService.GetAllProducts(); products = products.Where(p => p.Name.Contains(searchText)).ToList(); products = products.Skip(pageNumber * productsPerPage).Take(productsPerPage).ToList(); } var listProducts = products.ToList(); String[] allPrimaryImageLinks = await _productService.GetAllImages(products); //Retrieve all image links ViewBag.AllPrimaryImageLinks = allPrimaryImageLinks; // ----------------------------------------- ICollection <ProductAd> productAds = await _productService.GetProductAds(); ViewBag.ProductAds = productAds; //------- discountai ------------// DiscountListViewModel dlvm = await GetDiscountList(listProducts); ViewBag.HasDiscountList = dlvm.HasDiscountList; ViewBag.DiscountPriceList = dlvm.DiscountPriceList; ViewBag.DiscountEndDateList = dlvm.DiscountEndDateList; //------- atributai ------------// AttributeListViewModel alvm = await GetAttributeListInCategory(category); ViewBag.AttributeValues = alvm.AttributeValues; ViewBag.Attributes = alvm.Attributes; ViewBag.SelectedAttributeValueName = attributeName; return(View("Index", products)); }