void GetData(out ProductOrderBy sortBy, out SortOrder sortOrder, string sort) { sortBy = ProductOrderBy.DisplayOrder; sortOrder = SortOrder.Descending; switch (sort) { case "PruductName": sortBy = ProductOrderBy.ProductName; break; case "Date": sortBy = ProductOrderBy.DataCreated; break; case "Variety": sortBy = ProductOrderBy.BrandName; break; case "PriceDesc": sortBy = ProductOrderBy.Price; sortOrder = SortOrder.Descending; break; case "PriceAsc": sortBy = ProductOrderBy.Price; sortOrder = SortOrder.Ascending; break; case "None": default: sortBy = ProductOrderBy.DisplayOrder; sortOrder = SortOrder.Descending; break; } }
public static SelectList GetProductOrderByList(ProductOrderBy productOrderBy) { var list = new List <SelectListItem> { new SelectListItem { Text = "نام", Value = "Name" }, new SelectListItem { Text = "تعداد در انبار", Value = "StockCount" }, new SelectListItem { Text = "تعداد فروش", Value = "SellCount" }, new SelectListItem { Text = "تعداد مشاهده", Value = "ViewCount" }, new SelectListItem { Text = "تعداد رزرو شده در کارت", Value = "ReserveCount" }, new SelectListItem { Text = "قیمت", Value = "Price" }, new SelectListItem { Text = "درصد تخفیف", Value = "DiscountPercent" }, new SelectListItem { Text = "مینیمم مقدار هشدار", Value = "NotificationStockMinimun" } }; return(new SelectList(list, "Value", "Text", productOrderBy)); }
public virtual ActionResult List(bool freeSend = false, bool deleted = false, string term = "", int page = 1, int count = 10, Order order = Order.Descending, ProductOrderBy productOrderBy = ProductOrderBy.Name, long categoryId = 0, ProductType productType = ProductType.All) { #region Retrive Data int total; var products = _productService.DataList(out total, term, deleted, freeSend, page, count, categoryId, productOrderBy, order, productType); var model = new ProductListViewModel { CategoryId = categoryId, Order = order, ProductOrderBy = productOrderBy, PageCount = count, PageNumber = page, ProductList = products, ProductType = productType, Term = term, TotalProducts = total, Deleted = deleted, FreeSend = freeSend }; #endregion ViewBag.ProductOrderByList = DropDown.GetProductOrderByList(productOrderBy); ViewBag.CountList = DropDown.GetCountList(count); ViewBag.OrderList = DropDown.GetOrderList(order); PopulateCategoriesDropDownList(categoryId); return(PartialView(MVC.Admin.Product.Views._ListPartial, model)); }
public ProductsFilter(PageFilter pageFilter, string title, decimal minPrice, decimal maxPrice, bool @descending, ProductOrderBy orderBy) { Validator.Begin(pageFilter, nameof(pageFilter)) .NotDefault() .Map(minPrice, nameof(minPrice)) .IsGreaterOrEquals(0) .Map(maxPrice, nameof(maxPrice)) .IsGreaterOrEquals(minPrice) .ThrowApiException(nameof(ProductsFilter), nameof(ProductsFilter)); PageFilter = pageFilter; Title = title; MinPrice = minPrice; MaxPrice = maxPrice; Descending = @descending; OrderBy = orderBy; }
public async Task HandleSort(ProductOrderBy order) { foreach (var kv in TableHeaderModel) { if (kv.Key == order) { kv.Value.IsActive = true; } else { kv.Value.IsActive = false; } } Current = order; await LoadFromServerAsync(); }
public IEnumerable <ProductViewModel> DataList(out int total, string term, bool deleted, bool freeSend, int page, int count, long categoryId, ProductOrderBy productOrderBy, Order order, ProductType productType) { var selectedProducts = _products.AsNoTracking() .Include(a => a.Category) .Include(a => a.Values) .Include(a => a.Images) .AsQueryable(); if (deleted || freeSend) { selectedProducts = selectedProducts.Where(a => a.Deleted == deleted && a.IsFreeShipping == freeSend).AsQueryable(); } if (categoryId != 0) { selectedProducts = selectedProducts.Where(a => a.CategoryId == categoryId).AsQueryable(); } if (productType != ProductType.All) { selectedProducts = selectedProducts.Where(a => a.Type == productType).AsQueryable(); } if (!string.IsNullOrEmpty(term)) { selectedProducts = selectedProducts.Where(product => product.Name.Contains(term)).AsQueryable(); } if (order == Order.Asscending) { switch (productOrderBy) { case ProductOrderBy.Name: selectedProducts = selectedProducts.OrderBy(product => product.Name).AsQueryable(); break; case ProductOrderBy.DiscountPercent: selectedProducts = selectedProducts.OrderBy(product => product.DiscountPercent).AsQueryable(); break; case ProductOrderBy.NotificationStockMinimun: selectedProducts = selectedProducts.OrderBy(product => product.NotificationStockMinimum).AsQueryable(); break; case ProductOrderBy.Price: selectedProducts = selectedProducts.OrderBy(product => product.Price).AsQueryable(); break; case ProductOrderBy.ReserveCount: selectedProducts = selectedProducts.OrderBy(product => product.Reserve).AsQueryable(); break; case ProductOrderBy.SellCount: selectedProducts = selectedProducts.OrderBy(product => product.SellCount).AsQueryable(); break; case ProductOrderBy.StockCount: selectedProducts = selectedProducts.OrderBy(product => product.Stock).AsQueryable(); break; case ProductOrderBy.ViewCount: selectedProducts = selectedProducts.OrderBy(product => product.ViewCount).AsQueryable(); break; } } else { switch (productOrderBy) { case ProductOrderBy.Name: selectedProducts = selectedProducts.OrderByDescending(product => product.Name).AsQueryable(); break; case ProductOrderBy.DiscountPercent: selectedProducts = selectedProducts.OrderByDescending(product => product.DiscountPercent).AsQueryable(); break; case ProductOrderBy.NotificationStockMinimun: selectedProducts = selectedProducts.OrderByDescending(product => product.NotificationStockMinimum).AsQueryable(); break; case ProductOrderBy.Price: selectedProducts = selectedProducts.OrderByDescending(product => product.Price).AsQueryable(); break; case ProductOrderBy.ReserveCount: selectedProducts = selectedProducts.OrderByDescending(product => product.Reserve).AsQueryable(); break; case ProductOrderBy.SellCount: selectedProducts = selectedProducts.OrderByDescending(product => product.SellCount).AsQueryable(); break; case ProductOrderBy.StockCount: selectedProducts = selectedProducts.OrderByDescending(product => product.Stock).AsQueryable(); break; case ProductOrderBy.ViewCount: selectedProducts = selectedProducts.OrderByDescending(product => product.ViewCount).AsQueryable(); break; } } var totalQuery = selectedProducts.FutureCount(); var selectQuery = selectedProducts.Skip((page - 1) * count).Take(count) .Select(a => new ProductViewModel { ApplyCategoryDiscount = a.ApplyCategoryDiscount, CategoryName = a.Category.Name, Deleted = a.Deleted, DiscountPercent = a.DiscountPercent, Id = a.Id, IsFreeShipping = a.IsFreeShipping, Name = a.Name, NotificationStockMinimum = a.NotificationStockMinimum, Price = a.Price, PrincipleImagePath = a.PrincipleImagePath, Rate = a.Rate.TotalRating, Ratio = a.Ratio, ReserveCount = a.Reserve, SellCount = a.SellCount, Stock = a.Stock, ViewCount = a.ViewCount, AddedImages = a.Images.Any(), CompletedAttributes = a.Values.Any(), Notification = a.Stock - a.Reserve <= a.NotificationStockMinimum }).Future(); total = totalQuery.Value; var products = selectQuery.ToList(); return(products); }
internal async Task <IEnumerable <Product> > GetProductsAsync(int id, int limit, int start, ProductOrderBy orderBy = ProductOrderBy.Name, bool ascending = true) { ProductRepository repo = ProductRepository.Instance.Limit(limit); if (start > 0) { repo = repo.Offset(start); } return(await repo.OrderBy(orderBy.ToString(), ascending).SelectWhereAsync(p => p.BrandID == id)); }
/// <summary> /// 根据QueryString生成查询对象 /// </summary> /// <param name="queryString"></param> /// <returns></returns> public static ProductQuery GetQueryFromQueryString(NameValueCollection queryString) { ProductQuery query = new ProductQuery(); if (!GlobalSettings.IsNullOrEmpty(queryString["p"])) { try { query.Filter = (ProviderFilter)(int.Parse(queryString["p"])); } catch { query.Filter = null; } } //ProductName if (!GlobalSettings.IsNullOrEmpty(queryString["pn"])) { query.ProductNameFilter = queryString["pn"]; } //ProductID if (!GlobalSettings.IsNullOrEmpty(queryString["di"])) { query.ProductID = Convert.ToInt32(queryString["di"]); Product product = Products.GetProduct(query.ProductID.Value); if (product != null) { query.ProductNameFilter = product.ProductName; } } //BrandID if (!GlobalSettings.IsNullOrEmpty(queryString["bi"])) { query.BrandID = Convert.ToInt32(queryString["bi"]); } //IndustryID if (!GlobalSettings.IsNullOrEmpty(queryString["ii"])) { query.IndustryID = Convert.ToInt32(queryString["ii"]); } //CategoryID if (!GlobalSettings.IsNullOrEmpty(queryString["ci"])) { query.CategoryID = Convert.ToInt32(queryString["ci"]); } //CompanyID if (!GlobalSettings.IsNullOrEmpty(queryString["si"])) { query.CompanyID = Convert.ToInt32(queryString["si"]); } //HasPictures if (!GlobalSettings.IsNullOrEmpty(queryString["hp"])) { int pi = Convert.ToInt32(queryString["hp"]); query.HasPictures = (pi == 1); } //HasPrice if (!GlobalSettings.IsNullOrEmpty(queryString["pr"])) { int pr = Convert.ToInt32(queryString["pr"]); query.HasPrice = (pr == 1); } //HasPublished if (!GlobalSettings.IsNullOrEmpty(queryString["pb"])) { int pb = Convert.ToInt32(queryString["pb"]); query.HasPublished = (pb == 1); } //ProductOrderBy try { ProductOrderBy sortBy = (ProductOrderBy)Enum.Parse(typeof(ProductOrderBy), GlobalSettings.IsNullOrEmpty(queryString["sb"]) ? "1" : int.Parse(queryString["sb"]).ToString(), true); query.ProductOrderBy = sortBy; } catch { query.ProductOrderBy = ProductOrderBy.DisplayOrder; } // Sort Order try { SortOrder sortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), GlobalSettings.IsNullOrEmpty(queryString["so"]) ? "1" : int.Parse(queryString["so"]).ToString(), true); query.SortOrder = sortOrder; } catch { query.SortOrder = SortOrder.Ascending; } return(query); }
public async Task <List <Product> > Search(string query, int categoryID, int limit = 30, int start = 0, ProductOrderBy orderBy = ProductOrderBy.Name, bool ascending = true) { throw new NotImplementedException(); }
void BindData() { ProductQuery query = this.Query; lnkGrid.PostBackUrl = Request.RawUrl; lnkList.PostBackUrl = Request.RawUrl; lnkGrid.Attributes.Add("rel", "grid"); lnkList.Attributes.Add("rel", "list"); #region -Adapt Show- string s = Request.QueryString["s"]; if (!string.IsNullOrEmpty(s)) { switch (s) { case "grid": lnkGrid.CssClass = "showByGrid showBy showByGridActive"; lnkList.CssClass = "showByList showBy"; cpProduct.PageSize = 10; break; case "list": lnkList.CssClass = "showByList showBy showByListActive"; lnkGrid.CssClass = "showByGrid showBy"; cpProduct.PageSize = 50; break; } } else { cpProduct.PageSize = 10; s = "grid"; lnkGrid.CssClass = "showByGrid showBy showByGridActive"; lnkList.CssClass = "showByList showBy"; } #endregion #region -BindData- string sortBy = Request.QueryString["sortby"]; ProductOrderBy orderBy = ProductOrderBy.DisplayOrder; SortOrder sortOrder = SortOrder.Descending; if (!string.IsNullOrEmpty(sortBy)) { try { ddlSortBy.Items.FindByValue(sortBy).Selected = true; } catch { ddlSortBy.SelectedIndex = 0; } GetData(out orderBy, out sortOrder, sortBy); } query.ProductOrderBy = orderBy; query.SortOrder = sortOrder; query.PageSize = int.MaxValue; query.HasPublished = true; List <Product> prods = null; if (!IsSearch) { prods = Products.GetProducts(query).Records; } else { if (string.IsNullOrEmpty(query.ProductNameFilter)) { prods = Products.GetProducts(query).Records; } else { SearchResultDataSet <Product> _pros = ProductSearchManager.Search(query); prods = _pros.Records; pnlSearch.Visible = true; ltSearchDuration.Text = "搜索用时:" + _pros.SearchDuration.ToString() + "秒。"; } } if (prods == null || prods.Count == 0) { msgBox.ShowMsg("没有符合条件的产品存在!", System.Drawing.Color.Gray); return; } msgBox.HideMsg(); bool islogin = Context.User.Identity.IsAuthenticated; if (orderBy == ProductOrderBy.Price) { prods.Sort(new SortProductByPrice(sortOrder, (islogin ? Profile.AccountInfo.UserID : 0), islogin )); } if (s == "grid") { dlProduct2.Visible = false; dlProduct.Visible = true; cpProduct.DataSource = prods; cpProduct.BindToControl = dlProduct; dlProduct.DataSource = cpProduct.DataSourcePaged; dlProduct.DataBind(); } else { dlProduct.Visible = false; dlProduct2.Visible = true; cpProduct.DataSource = prods; cpProduct.BindToControl = dlProduct2; dlProduct2.DataSource = cpProduct.DataSourcePaged; dlProduct2.DataBind(); } #endregion }
public List <Product> listProducts(string search = "", string artistId = "", int currentPage = 0, int totalPerPage = 0, ProductOrderBy orderBy = ProductOrderBy.title) { IQueryable <Product> rows = db.Products.Include(x => x.artist); if (!string.IsNullOrWhiteSpace(search)) { rows = rows.Where(x => x.title.Contains(search) || x.artist.fullName.Contains(search)); } switch (orderBy) { case ProductOrderBy.rating: rows = rows.OrderByDescending(x => x.avgStars); break; case ProductOrderBy.quantitySold: rows = rows.OrderByDescending(x => x.quantitySold); break; default: rows = rows.OrderBy(x => x.title); break; } if (totalPerPage > 0) { rows = rows.Skip(totalPerPage * currentPage).Take(totalPerPage); } List <Product> result = null; try { result = rows.ToList(); } catch (Exception ex) { result = null; } return(result); }
public static IQueryable <ProductListDto> OrderProductsBy(this IQueryable <ProductListDto> products, ProductOrderBy orderBy) { if (products == null || products.Count() < 1) { return(products); } switch (orderBy) { case ProductOrderBy.Default: return(products.OrderByDescending(product => product.Id)); case ProductOrderBy.ByPublicationYear: return(products.OrderByDescending(product => product.PublishedOn)); case ProductOrderBy.ByPriceLowestFirst: return(products.OrderBy(product => product.ActualPrice)); case ProductOrderBy.ByPriceHigestFirst: return(products.OrderByDescending(product => product.ActualPrice)); default: throw new ArgumentOutOfRangeException(nameof(orderBy), orderBy, null); } }