Exemplo n.º 1
0
        public async Task <ProductViewModel> Handle(GetAllProductQuery request, CancellationToken cancellationToken)
        {
            var   cartCount = _cartService.GetCartCount();
            Torce torce     = new Torce(_context);

            var products = _context.Products
                           .Include(c => c.Category)
                           .Include(c => c.District)
                           .Include(x => x.Photo)
                           .AsEnumerable().Select(x =>
            {
                if (x.Photo != null)
                {
                    x.Photo.Path = "https://localhost:44318" + x.Photo.Path;
                }

                return(x);
            }).ToList();

            var categories = await _productService.GetAllCategoriesAsync();

            var districts = await _productService.GetAllDistrictsAsync();

            var domains = _productService.GetParentCategoryNames();

            var totalPrice = _cartService.GetCartTotalPrice();

            var productView = new ProductViewModel
            {
                Products    = products,
                Category    = categories,
                District    = districts,
                DistinctCat = domains,
                BaseProduct = products,  //it will always remain same as it is inherited
                CartCount   = cartCount,
                TotalPrice  = totalPrice,
                Sellers     = await _context.Sellers.ToListAsync()
            };

            return(await Task.FromResult(productView));
        }
Exemplo n.º 2
0
        public IActionResult Index(SearchVM searchVm)
        {
            CartService cs = new CartService(_httpContextAccessor, _context);

            var   cartCount = cs.GetCartCount();
            Torce torce     = new Torce(_context);

            //            000
            if (searchVm.Text != null && searchVm.PriceRange != null && searchVm.DistrictId != null)
            {
                this.product = torce.SearchProducts(searchVm.Text, searchVm.PriceRange, searchVm.DistrictId);
            }

            //            001
            if (searchVm.Text != null && searchVm.PriceRange != null && searchVm.DistrictId == null)
            {
                this.product = torce.SearchProducts(searchVm.Text, searchVm.PriceRange);
            }
            //            010
            if (searchVm.Text != null && searchVm.PriceRange == null && searchVm.DistrictId != null)
            {
                this.product = torce.SearchProducts(searchVm.Text, searchVm.DistrictId);
            }

            //            011
            if (searchVm.Text != null && searchVm.PriceRange == null && searchVm.DistrictId == null)
            {
                this.product = torce.SearchProducts(searchVm.Text);
            }

            //            100
            if (searchVm.Text == null && searchVm.PriceRange != null && searchVm.DistrictId != null)
            {
                this.product = torce.SearchProducts2(searchVm.PriceRange, searchVm.DistrictId);
            }


            //            101
            if (searchVm.Text == null && searchVm.PriceRange != null && searchVm.DistrictId == null)
            {
                this.product = torce.SearchProducts2(searchVm.PriceRange);
            }
            //            110
            if (searchVm.Text == null && searchVm.PriceRange == null && searchVm.DistrictId != null)
            {
                this.product = torce.SearchProducts3(searchVm.DistrictId);
            }

            if (searchVm.Text == null && searchVm.PriceRange == null && searchVm.DistrictId == null)
            {
                this.product = torce.SearchProducts();
            }


            var categories = ps.GetAllCategories();
            var districts  = ps.GetAllDistricts();
            var domains    = ps.GetCategoryByDomain();
            var totalPrice = cs.GetCartTotalPrice();



            var productView = new ProductViewModel
            {
                Products    = this.product,
                Category    = categories,
                District    = districts,
                DistinctCat = domains,
                BaseProduct = this.product,  //it will always remain same as it is inherited
                CartCount   = cartCount,
                TotalPrice  = totalPrice,
                Sellers     = _context.Sellers.ToList()
            };

            return(View(productView));
        }