public async Task <IViewComponentResult> InvokeAsync ( int numberOfProducts, string Title, EnumDisplayModeProducts displayModeProducts = EnumDisplayModeProducts.Card, string TextSeach = "", long MasterId = -1, long CategoryId = -1, EnumOrderByProduct OrderBy = EnumOrderByProduct.NewestToOldest, bool EnabledPaging = false, bool EnabledSorting = false, int pageNumber = 1 ) { var newProducts = await Task.Run(() => _queryDispatcher.Dispatch <DtoProductsAdvanacedQuery>(new ProductsAdvanacedQuery { number = numberOfProducts, TextSeach = TextSeach, MasterId = MasterId, CategoryId = CategoryId, OrderBy = OrderBy, EnabledPaging = EnabledPaging, EnabledSorting = EnabledSorting, PageNumber = pageNumber })); newProducts.Title = Title; newProducts.DisplayModeProducts = displayModeProducts; return(View(newProducts.DisplayModeProducts.ToString(), newProducts)); }
private IQueryable <MasterProduct> CreateQuery(string TextSeach, long MasterId, long CategoryId, EnumOrderByProduct orderBy) { IOrderedQueryable <MasterProduct> query = null; switch (orderBy) { case EnumOrderByProduct.LowestToHighestPrice: query = _termeDbContext.MasterProducts.OrderBy(x => x.Price); break; case EnumOrderByProduct.HighestToLowestPrice: query = _termeDbContext.MasterProducts.OrderByDescending(x => x.Price); break; case EnumOrderByProduct.NewestToOldest: query = _termeDbContext.MasterProducts.OrderByDescending(x => x.Id); break; case EnumOrderByProduct.OldestToNewest: query = _termeDbContext.MasterProducts.OrderBy(x => x.Id); break; case EnumOrderByProduct.MostDiscount: query = _termeDbContext.MasterProducts.OrderByDescending(x => x.Discount); break; default: query = _termeDbContext.MasterProducts.OrderByDescending(x => x.Id); break; } IQueryable <MasterProduct> FilteredQuery = query; if (TextSeach != "") { FilteredQuery = FilteredQuery.Where(b => b.Name.Contains(TextSeach)); } if (MasterId > 0) { FilteredQuery = FilteredQuery.Where(b => b.MasterId == MasterId); } if (CategoryId > 0) { FilteredQuery = FilteredQuery.Where(b => b.CategoryId == CategoryId); } return(FilteredQuery); }
public DtoProductsAdvanacedQuery GetNewestProductsLimited(int number, string TextSeach, long MasterId, long CategoryId, EnumOrderByProduct orderBy, bool enabledPaging, int pageNumber, bool enabledSorting) { IQueryable <MasterProduct> FilteredQueryCount = CreateQuery(TextSeach, MasterId, CategoryId, orderBy); int cntProducts = FilteredQueryCount.Count(); int cntPages = ((cntProducts - 1) / number) + 1; int cntSkip = pageNumber <= 1 ? 0 : (pageNumber - 1) * number; IQueryable <MasterProduct> FilteredQuery = CreateQuery(TextSeach, MasterId, CategoryId, orderBy); var briefProductCollection = FilteredQuery.Skip(cntSkip).Take(number).Select(aa => new DtoProductBrief { ProductId = aa.Id, Name = aa.Name, Price = aa.Price, Discount = aa.Discount, PhotoUrl = aa.MainPhoto.Url, ShortDescription = aa.ShortDescription, MasterFullName = aa.Master.FirstName + " " + aa.Master.LastName, MasterId = aa.MasterId }).AsNoTracking().ToList(); return(new DtoProductsAdvanacedQuery { DtoProductBriefCollection = briefProductCollection, CountPages = cntPages, CurrentPage = pageNumber, TextSeach = TextSeach, OrderByProduct = orderBy, MasterId = MasterId, CategoryId = CategoryId, EnabledPaging = enabledPaging, EnabledSorting = enabledSorting }); }