예제 #1
0
        public static SelectList GetSearchFilters(PSFilter seleted)
        {
            var list = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "انتخاب کنید", Value = "All"
                },
                new SelectListItem {
                    Text = "جدیدترین ها", Value = "New"
                },
                new SelectListItem {
                    Text = "پرفروش ترین ها", Value = "MoreSell"
                },
                new SelectListItem {
                    Text = "محبوب ترین ها", Value = "Beloved"
                },
                new SelectListItem {
                    Text = "پربازدید ترین ها", Value = "MoreView"
                },
                new SelectListItem {
                    Text = "تخفیف دار ها", Value = "HasDiscount"
                },
                new SelectListItem {
                    Text = "محصولات موجود", Value = "IsInStock"
                },
                new SelectListItem {
                    Text = "محصولات با ارسال رایگان", Value = "FreeSend"
                }
            };

            return(new SelectList(list, "Value", "Text", seleted));
        }
        public virtual ActionResult Index(long categoryId, int page, int count, PSFilter filter,
                                          string keyword
                                          )
        {
            int total;
            var products = _productService.DataListSearch(out total, keyword.RemoveHtmlTags(), page, count, filter, categoryId);

            ViewBag.Counts  = DropDown.GetSearchPageCount(count);
            ViewBag.Filters = DropDown.GetSearchFilters(filter);
            var model = new SearchViewModel
            {
                Products   = products,
                CategoryId = categoryId,
                Term       = keyword,
                Count      = count,
                Filter     = filter,
                Page       = page,
                Total      = total
            };

            return(View(model));
        }
예제 #3
0
        public IEnumerable <ProductSectionViewModel> DataListSearch(out int total, string term, int page,
                                                                    int count, PSFilter filtr, long categoryId)
        {
            var selectedProducts =
                _products.AsNoTracking().Where(a => !a.Deleted)
                .Include(a => a.Category).AsQueryable();

            if (categoryId != 0)
            {
                selectedProducts = selectedProducts.Where(a => a.CategoryId == categoryId).AsQueryable();
            }

            if (!string.IsNullOrEmpty(term))
            {
                selectedProducts = selectedProducts.Where(product => product.Name.Contains(term)).AsQueryable();
            }
            switch (filtr)
            {
            case PSFilter.All:
                selectedProducts = selectedProducts.OrderByDescending(a => a.Id).AsQueryable();
                break;

            case PSFilter.New:
                selectedProducts = selectedProducts.OrderByDescending(a => a.AddedDate).AsQueryable();
                break;

            case PSFilter.MoreView:
                selectedProducts = selectedProducts.OrderByDescending(a => a.ViewCount).AsQueryable();
                break;

            case PSFilter.MoreSell:
                selectedProducts = selectedProducts.OrderByDescending(a => a.SellCount).AsQueryable();
                break;

            case PSFilter.Beloved:
                selectedProducts = selectedProducts.OrderByDescending(a => a.Rate.TotalRaters).ThenByDescending(a => a.Rate.AverageRating).AsQueryable();
                break;

            case PSFilter.IsInStock:
                selectedProducts =
                    selectedProducts.Where(a => a.Stock - a.Reserve >= a.Ratio)
                    .OrderByDescending(a => a.Id)
                    .AsQueryable();
                break;

            case PSFilter.HasDiscount:
                selectedProducts =
                    selectedProducts.Where(a => a.DiscountPercent + a.Category.DiscountPercent > 0)
                    .OrderByDescending(a => a.Id)
                    .AsQueryable();
                break;

            case PSFilter.FreeSend:
                selectedProducts =
                    selectedProducts.Where(a => a.IsFreeShipping)
                    .OrderByDescending(a => a.Id)
                    .AsQueryable();
                break;
            }

            var totalQuery  = selectedProducts.FutureCount();
            var selectQuery = selectedProducts.Skip((page - 1) * count).Take(count)
                              .Select(a => new ProductSectionViewModel
            {
                AvrageRate         = a.Rate.AverageRating,
                Id                 = a.Id,
                IsFreeShipping     = a.IsFreeShipping,
                IsInStock          = a.Stock - a.Reserve >= a.Ratio,
                Name               = a.Name,
                Price              = a.Price,
                TotalRaters        = a.Rate.TotalRaters ?? 0,
                Ratio              = a.Ratio,
                PrincipleImagePath = a.PrincipleImagePath,
                SellCount          = a.SellCount,
                TotalDiscount      = a.ApplyCategoryDiscount ? a.DiscountPercent + a.Category.DiscountPercent : a.DiscountPercent,
                ViewCount          = a.ViewCount
            }).Future();

            total = totalQuery.Value;
            var products = selectQuery.ToList();

            return(products);
        }