Пример #1
0
        public List <Product> GetProductSearch(Model.ProdSearch prodSearch)
        {
            var list = db.Products.Where(n => n.IsActive == true).OrderByDescending(x => x.Id).ToList();

            if (prodSearch != null)
            {
                if (!string.IsNullOrEmpty(prodSearch.ProductSKU))
                {
                    list = list.Where(x => x.ProductSKU.ToLower().Equals(prodSearch.ProductSKU.ToLower()) && x.IsActive == true).ToList();
                }
                if (!string.IsNullOrEmpty(prodSearch.StyleSKU))
                {
                    list = list.Where(x => x.StyleSKU.ToLower().Contains(prodSearch.StyleSKU.ToLower()) && x.IsActive == true).ToList();
                }
            }
            return(list.RemoveReferences());
        }
Пример #2
0
        public ServiceResult <List <Product> > GetProducts(Model.ProdSearch prodSearch)
        {
            var pageSize = 6;
            ServiceResult <List <Product> > model = new ServiceResult <List <Product> >();

            var list = db.Products.Where(x => x.IsActive == true && x.IsAllowZero == false)
                       .Include(x => x.Season);
            List <Product> Temp = list.ToList();

            if (prodSearch != null)
            {
                if (prodSearch.IsActive == false)
                {
                    list = db.Products.Where(n => n.IsActive == false);
                }

                if (!string.IsNullOrEmpty(prodSearch.Colors))
                {
                    string colors = prodSearch.Colors;
                    if (colors != "null")
                    {
                        string[] values = colors.Split(',');
                        var      l      = values.Count();
                        for (int i = 0; i < l; i++)
                        {
                            var k    = 0;
                            var vals = values[i];
                            k = Convert.ToInt32(vals);
                            if (vals != "")
                            {
                                list = list.Where(x => x.ColorID == k);
                                Temp.AddRange(list.Where(x => x.ColorID == k));
                                Temp.AddRange(list.Where(x => x.Color.Code == vals));
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(prodSearch.AutocompleteProductSKU))
                {
                    // Temp.AddRange(list.Where(x => x.ProductSKU == prodSearch.AutocompleteProductSKU));
                    list = list.Where(x => x.ProductSKU.Contains(prodSearch.AutocompleteProductSKU));
                }
                if (!string.IsNullOrEmpty(prodSearch.AutocompleteStyleSKU))
                {
                    if (!string.IsNullOrEmpty(prodSearch.AutocompleteProductSKU))
                    {
                        list = list.Where(x => x.ProductSKU.Contains(prodSearch.AutocompleteProductSKU) && x.StyleSKU.Contains(prodSearch.AutocompleteStyleSKU));
                    }
                    else
                    {
                        list.Where(x => x.StyleSKU.Contains(prodSearch.AutocompleteStyleSKU));
                    }
                }
                if (!string.IsNullOrEmpty(prodSearch.AutocompleteSeason))
                {
                    // Temp.AddRange(list.Where(x => x.Season.Code == prodSearch.AutocompleteSeason));
                    list = list.Where(x => x.Season.Code.Contains(prodSearch.AutocompleteSeason));
                }
                if (prodSearch.MaxPrice <= 999 && prodSearch.MinPrice >= 30)
                {
                    //Temp.AddRange(list.Where(x => x.CostPrice >= prodSearch.MinPrice && x.CostPrice <= prodSearch.MaxPrice));
                    list = list.Where(x => x.CostPrice >= prodSearch.MinPrice && x.CostPrice <= prodSearch.MaxPrice);
                }
                if (prodSearch.ProdCat1ID > 0)
                {
                    list = list.Where(x => x.ProdCat1ID == prodSearch.ProdCat1ID);
                }
                if (prodSearch.ProdCat2ID > 0)
                {
                    list = list.Where(x => x.ProdCat2ID == prodSearch.ProdCat2ID);
                }
                if (prodSearch.ProdCat3ID > 0)
                {
                    list = list.Where(x => x.ProdCat3ID == prodSearch.ProdCat3ID);
                }
                if (prodSearch.ProdCat4ID > 0)
                {
                    list = list.Where(x => x.ProdCat4ID == prodSearch.ProdCat4ID);
                }
            }
            var result = list.ToList();
            int count  = result.Count();
            var items  = result.OrderByDescending(x => x.Id).Skip(((prodSearch.Page ?? 1) - 1) * pageSize).Take(pageSize).ToList();

            model.data = items.Select(x => new Product
            {
                Id           = x.Id,
                PrimaryImage = x.PrimaryImage,
                StyleSKU     = x.StyleSKU,
                CostPrice    = x.CostPrice,
                ProductSKU   = x.ProductSKU,
                Season       = x.Season
            }).ToList().RemoveReferences();
            model.TotalCount = count;
            return(model);
        }