Exemplo n.º 1
0
        public IQueryable <Stock> GetStockProducts(IQueryable <Stock> stockProducts, FilterParametersProducts filter)
        {
            //var categories = new List<int>();

            //if (filter.Categories != null)
            //{
            //    var categoriesStrings = filter.Categories.Split(';');

            //    foreach (var category in categoriesStrings)
            //    {
            //        categories.Add(Convert.ToInt32(category));
            //    }
            //}

            stockProducts = stockProducts.Where(p => filter.CategoriesList == null || filter.CategoriesList.Contains(p.Product.Category.ID));

            if (!String.IsNullOrEmpty(filter.Name))
            {
                stockProducts = stockProducts.Where(c => c.Product.Name.ToUpper().Contains(filter.Name.ToUpper()));
            }

            if (filter.MinPrice > 0)
            {
                stockProducts = stockProducts.Where(c => c.Product.Price >= filter.MinPrice);
            }

            if (filter.MaxPrice > 0)
            {
                stockProducts = stockProducts.Where(c => c.Product.Price <= filter.MaxPrice);
            }

            return(stockProducts);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> SearchList([FromForm] FilterParametersProducts filter, [FromForm] int productPage = 1)
        {
            var products = _repository.Products;

            products = _filterConditions.GetProducts(products, filter);

            var categories = new List <int>();

            if (!String.IsNullOrEmpty(filter.Categories))
            {
                var categoriesStrings = filter.Categories.Split(';');

                foreach (var category in categoriesStrings)
                {
                    categories.Add(Convert.ToInt32(category));
                }
            }

            filter.CategoriesList = categories;

            foreach (var p in products)
            {
                if (_stockRepository.StockItems.FirstOrDefault(pr => pr.Product == p && pr.Quantity > 0) != null)
                {
                    p.IsInStock = true;
                }
            }

            var paging = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = PageSize,
                TotalItems   = filter.Categories == null?
                               products.Count() :
                                   products.Where(e =>
                                                  categories.Contains(e.Category.ID)).Count()
            };

            if (products.Count() == 0)
            {
                return(BadRequest("No result"));
            }

            return(Ok(new ProductsListViewModel
            {
                Products = products
                           .Skip((productPage - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = paging,
                CurrentFilter = filter,
                Categories = _repository.Products
                             .Select(x => x.Category)
                             .Distinct()
                             .OrderBy(x => x).ToList()
            }));
        }
Exemplo n.º 3
0
        public ViewResult List(FilterParametersProducts filter, int productPage = 1, bool IsHot = false)
        {
            var products = _repository.Products;

            foreach (var p in products)
            {
                p.Categories = _dbCategories.Entity.FirstOrDefault(o => o.Id == p.CategoriesID);
            }

            if (filter.Categories != null)
            {
                TempData["SelectedCategory"] = filter.Categories[0];
            }
            if (filter.Countries != null)
            {
                TempData["SelectedCountry"] = String.Join("", filter.Countries);
            }

            filter.IsHot = IsHot;

            TempData["MaxPrice"] = filter.MaxPrice;
            TempData["MinPrice"] = filter.MinPrice;
            TempData["MinDate"]  = filter.MinDate;
            TempData["MaxDate"]  = filter.MaxDate;
            TempData["Hot"]      = filter.IsHot;

            var productsList = _filterConditions.GetProducts(products, filter);

            foreach (var p in productsList)
            {
                if (_stockRepository.StockItems.FirstOrDefault(pr => pr.Product == p && pr.Quantity > 0) != null)
                {
                    p.IsInStock = true;
                }
            }

            var paging = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = PageSize,
                TotalItems   = filter.Categories == null?
                               productsList.Count() :
                                   productsList.Where(e =>
                                                      filter.Categories.Contains(e.Categories.Name)).Count()
            };

            return(View(new ProductsListViewModel
            {
                Products = productsList
                           .Skip((productPage - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = paging,
                CurrentFilter = filter
            }));
        }
        public async Task <ViewResult> List(FilterParametersProducts filter, int productPage = 1)
        {
            try
            {
                HttpResponseMessage response = null;

                using (var httpClient = new HttpClient())
                {
                    MultipartFormDataContent data = new MultipartFormDataContent();

                    data.Add(new StringContent(filter.Name), "Name");
                    data.Add(new StringContent(filter.MinPrice.ToString()), "MinPrice");
                    data.Add(new StringContent(filter.MaxPrice.ToString()), "MaxPrice");
                    data.Add(new StringContent(filter.Category.ToString()), "Category");
                    data.Add(new StringContent(productPage.ToString()), "productPage");

                    string categoryCostyl = String.Empty;

                    if (filter.Category > 0)
                    {
                        categoryCostyl += filter.Category.ToString() + ';';
                    }

                    if (filter.CategoriesList != null)
                    {
                        foreach (var category in filter.CategoriesList)
                        {
                            categoryCostyl += category.ToString() + ';';
                        }
                    }

                    if (!String.IsNullOrEmpty(categoryCostyl))
                    {
                        categoryCostyl = categoryCostyl.Substring(0, categoryCostyl.Length - 1);
                    }


                    data.Add(new StringContent(categoryCostyl), "Categories");

                    //     httpClient.DefaultRequestHeaders.Add("Authorization", TokenKeeper.Token);
                    response = await httpClient.PostAsync(_apiPathList, data);

                    var json = await response.Content.ReadAsStringAsync();

                    var obj = JsonConvert.DeserializeObject <ProductsListViewModel>(json);

                    return(View(obj));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public async Task <ViewResult> SearchList(FilterParametersProducts filter, int productPage = 1)
        {
            try
            {
                HttpResponseMessage response = null;

                using (var httpClient = new HttpClient())
                {
                    MultipartFormDataContent data = new MultipartFormDataContent();

                    data.Add(new StringContent(filter.Name), "Name");
                    data.Add(new StringContent(filter.MinPrice.ToString()), "MinPrice");
                    data.Add(new StringContent(filter.MaxPrice.ToString()), "MaxPrice");
                    data.Add(new StringContent(filter.Category.ToString()), "Category");
                    data.Add(new StringContent(productPage.ToString()), "productPage");

                    string categoryCostyl = String.Empty;

                    if (filter.Categories != null)
                    {
                        foreach (var category in filter.Categories)
                        {
                            categoryCostyl += category.ToString() + ';';
                        }

                        categoryCostyl = categoryCostyl.Substring(0, categoryCostyl.Length - 2);
                    }


                    data.Add(new StringContent(categoryCostyl), "Categories");

                    httpClient.DefaultRequestHeaders.Authorization =
                        new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", TokenKeeper.Token);
                    response = await httpClient.PostAsync(_apiPathSearchList, data);

                    if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                    {
                        TempData["message"] = $"Поиск не дал результатов";

                        return(View(new AdminProductsListViewModel()));
                    }

                    var json = await response.Content.ReadAsStringAsync();

                    var obj = JsonConvert.DeserializeObject <AdminProductsListViewModel>(json);

                    return(View(obj));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task <ViewResult> Index(FilterParametersProducts filter, int productPage = 1)
        {
            ViewBag.Current = "Products";

            try
            {
                HttpResponseMessage response = null;

                using (var httpClient = new HttpClient())
                {
                    MultipartFormDataContent data = new MultipartFormDataContent();

                    data.Add(new StringContent(filter.Name), "Name");
                    data.Add(new StringContent(filter.MinPrice.ToString()), "MinPrice");
                    data.Add(new StringContent(filter.MaxPrice.ToString()), "MaxPrice");
                    data.Add(new StringContent(filter.Category.ToString()), "Category");
                    data.Add(new StringContent(productPage.ToString()), "productPage");

                    string categoryCostyl = String.Empty;

                    if (filter.Categories != null)
                    {
                        foreach (var category in filter.Categories)
                        {
                            categoryCostyl += category.ToString() + ';';
                        }

                        categoryCostyl = categoryCostyl.Substring(0, categoryCostyl.Length - 2);
                    }


                    data.Add(new StringContent(categoryCostyl), "Categories");

                    httpClient.DefaultRequestHeaders.Authorization =
                        new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", TokenKeeper.Token);
                    response = await httpClient.PostAsync(_apiPathGetData, data);

                    var json = await response.Content.ReadAsStringAsync();

                    var obj = JsonConvert.DeserializeObject <AdminProductsListViewModel>(json);

                    if (obj.CurrentFilter.CategoriesList == null)
                    {
                        obj.CurrentFilter.CategoriesList = new List <int>();
                    }

                    return(View(obj));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult> SearchList([FromForm] FilterParametersProducts filter, [FromForm] int productPage = 1)
        {
            var categories = new List <int>();

            if (filter.Categories != null)
            {
                var categoriesStrings = filter.Categories.Split(';');

                foreach (var category in categoriesStrings)
                {
                    categories.Add(Convert.ToInt32(category));
                }

                filter.CategoriesList = categories;
            }

            var stock = _stockRepository.StockItems;

            stock = _filterConditions.GetStockProducts(stock, filter);

            var paging = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = PageSize,
                TotalItems   = filter.Categories == null?
                               stock.Count() :
                                   stock.Where(e =>
                                               categories.Contains(e.Product.Category.ID)).Count()
            };

            if (stock.Count() == 0)
            {
                return(BadRequest("No results"));
            }

            return(Ok(new AdminProductsListViewModel
            {
                Stock = stock
                        .Skip((productPage - 1) * PageSize)
                        .Take(PageSize),
                PagingInfo = paging,
                CurrentFilter = filter,
                Categories = _stockRepository.StockItems
                             .Select(x => x.Product.Category)
                             .Distinct()
                             .OrderBy(x => x).ToList()
            }));
        }
Exemplo n.º 8
0
        public IViewComponentResult Invoke()
        {
            ViewBag.SelectedCategory = RouteData?.Values["category"];
            ViewBag.SelectedCountry  = RouteData?.Values["country"];


            var filter = new FilterParametersProducts
            {
                Categories = _dbCategories.Entity.Select(o => o.Name)
                             .OrderBy(x => x).ToList(),
                Countries = _dbLocation.Entity.Select(o => o.Country).Distinct()
                            .OrderBy(x => x).ToList()
            };

            return(View(filter));
        }
Exemplo n.º 9
0
        public IQueryable <Stock> GetStockProducts(IQueryable <Stock> stockProducts, FilterParametersProducts filter)
        {
            stockProducts = stockProducts.Where(p => filter.Categories == null || filter.CategoriesList.Contains(p.Product.Category.ID));

            if (!String.IsNullOrEmpty(filter.Name))
            {
                stockProducts = stockProducts.Where(c => c.Product.Name.ToUpper().Contains(filter.Name.ToUpper()));
            }

            if (filter.MinPrice > 0)
            {
                stockProducts = stockProducts.Where(c => c.Product.Price >= filter.MinPrice);
            }

            if (filter.MaxPrice > 0)
            {
                stockProducts = stockProducts.Where(c => c.Product.Price <= filter.MaxPrice);
            }

            return(stockProducts);
        }
Exemplo n.º 10
0
        public async Task <ActionResult> List([FromForm] FilterParametersProducts filter, [FromForm] int productPage = 1)
        {
            var categories = new List <int>();

            if (!String.IsNullOrEmpty(filter.Categories))
            {
                var categoriesStrings = filter.Categories.Split(';');

                foreach (var category in categoriesStrings)
                {
                    categories.Add(Convert.ToInt32(category));
                }

                filter.CategoriesList = categories;

                int addedCount = 0;

                do
                {
                    addedCount = 0;
                    List <int> toAdd = new List <int>();

                    foreach (int categoryID in categories)
                    {
                        foreach (var id in _categoryRepository.Categories
                                 .FirstOrDefault(c => c.ID == categoryID).Children
                                 .Where(c => !categories.Contains(c.ID))
                                 .Select(c => c.ID))
                        {
                            toAdd.Add(id);
                            addedCount++;
                        }
                    }

                    categories.AddRange(toAdd);
                }while (addedCount > 0);

                filter.CategoriesList = categories;
            }

            var products = _repository.Products;

            products = _filterConditions.GetProducts(products, filter);

            foreach (var p in products)
            {
                if (_stockRepository.StockItems.FirstOrDefault(pr => pr.Product == p && pr.Quantity > 0) != null)
                {
                    p.IsInStock = true;
                }
            }

            var paging = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = PageSize,
                TotalItems   = filter.Categories == null?
                               products.Count() :
                                   products.Where(e =>
                                                  categories.Contains(e.Category.ID)).Count()
            };

            return(Ok(new ProductsListViewModel
            {
                Products = products
                           .Skip((productPage - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = paging,
                CurrentFilter = filter
            }));
        }
        public IQueryable <Product> GetProducts(IQueryable <Product> products, FilterParametersProducts filter)
        {
            if (filter.Categories != null)
            {
                foreach (var c in filter.Categories)
                {
                    products = products.Where(p => c.Contains(p.Categories.Name));
                }
            }

            if (!String.IsNullOrEmpty(filter.Name))
            {
                products = products.Where(c => c.Name.ToUpper().Contains(filter.Name.ToUpper()));
            }

            if (filter.MinPrice > 0)
            {
                products = products.Where(c => (decimal)c.PriceSell >= filter.MinPrice);
            }

            if (filter.MaxPrice > 0)
            {
                products = products.Where(c => (decimal)c.PriceSell <= filter.MaxPrice);
            }

            var vouchers = _dbVoucher.Entity;

            if (filter.IsHot)
            {
                vouchers = vouchers.Where(o => o.Status == VoucherStatus.Hot);
            }

            if (filter.Countries != null)
            {
                var strCountries = String.Join("", filter.Countries);

                var countries = _dbLocation.Entity
                                .Where(tmp => tmp.Country.Contains(strCountries)).ToArray();

                if (filter.Countries.Count > 1)
                {
                    countries = _dbLocation.Entity.Where(tmp => IsContains(filter.Countries, tmp.Country)).ToArray();
                }


                var vouchersFrom = vouchers;

                foreach (var from in countries)
                {
                    var conreteVouchersFrom = vouchers.Where(tour => tour.LocationFromId == from.Id);
                    vouchersFrom = vouchersFrom.Except(conreteVouchersFrom);
                }

                var vouchersTo = vouchers;
                foreach (var to in countries)
                {
                    var locVoucher = _dbLocationVoucher.Entity.Where(loc => loc.LocationId == to.Id);
                    foreach (var lv in locVoucher)
                    {
                        var conreteVouchersTo = vouchers.Where(tour => tour.ID == lv.VoucherId);
                        vouchersTo = vouchersTo.Except(conreteVouchersTo);
                    }
                }

                vouchers = vouchers.Except(vouchersFrom.Intersect(vouchersTo));
            }


            if (filter.MinDate > DateTime.MinValue)
            {
                vouchers = vouchers.Where(tour => tour.DateStart > filter.MinDate);
            }
            if (filter.MaxDate > DateTime.MinValue)
            {
                vouchers = vouchers.Where(tour => tour.DateEnd < filter.MaxDate);
            }

            IQueryable <Product> prList = products;

            foreach (var a in vouchers)
            {
                var conreteProduct = products.Where(d => d.ID == a.ProductId);
                prList = prList.Except(conreteProduct);
            }

            products = products.Except(prList);

            return(products);
        }