Пример #1
0
        public ActionResult Products(ShopProductsViewModel model, int?stockId, string returnUrl = "")
        {
            int?storeID = TempData["storeId"] as int?;
            int?catID   = TempData["catId"] as int?;

            if (model.Qty == 0 || ModelState.IsValid)
            {
                if (model.Qty == 0)
                {
                    model.Qty = 1;
                }
                AddToCart(new CartAddViewModel {
                    ItemId = (int)stockId, Qty = model.Qty
                });
                TempData["AddedToCart"] = true;
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                return(RedirectToAction("Products", new { storeId = storeID, catId = catID, flag = true }));
            }

            TempData["storeId"] = storeID;
            TempData["catId"]   = catID;
            return(View(model));
        }
Пример #2
0
        public ShopProductsViewModel GetShopProducts(int categoryID)
        {
            ShopProductsViewModel shopProductsViewModel = new ShopProductsViewModel();

            Shop shop = dbContext.Shops.FirstOrDefault(x => x.CategoryID == categoryID);

            if (shop != null)
            {
                shopProductsViewModel.Name = shop.Name;
            }

            IQueryable <Product> shopProducts = dbContext.Products.Where(x => x.CategoryID == categoryID);

            foreach (Product dbProduct in shopProducts)
            {
                Models.DBObjects.Product productModel = new Models.DBObjects.Product();

                productModel.Name        = dbProduct.Name;
                productModel.Description = dbProduct.Description;
                productModel.DailyPrice  = dbProduct.DailyPrice;
                productModel.Stock       = dbProduct.Stock;

                shopProductsViewModel.Products.Add(productModel);
            }
            return(shopProductsViewModel);
        }
Пример #3
0
        public ActionResult ProductsShop(int shopID, int categoryID, ShopProductsFilter filter = null)
        {
            if (filter == null)
            {
                filter = new ShopProductsFilter {
                    CategoryID = categoryID, ShopID = shopID
                };
            }
            var result = new ShopProductsViewModel();

            var shopProducts = _shopService.GetShopProducts(filter.ShopID, filter.CategoryID).Sort(filter.SortOrder, filter.SortOptions, false);

            result.Category = _productService.GetCategory(categoryID);
            result.Products = shopProducts.Select(q => q.Product).ToPagedList(filter.Page, filter.PageSize);
            result.Filter   = filter;

            return(View(result));
        }
Пример #4
0
        public ActionResult FiltersPartial(ShopProductsViewModel prodModel)
        {
            prodModel.FilterViewModel.PriceSelection.PriceSelectionItems
                = new List <PriceSelectionItem>
                {
                new PriceSelectionItem
                {
                    Id          = 1,
                    DisplayName = "0 to 1000",
                    MinPrice    = 0,
                    MaxPrice    = 1000
                },
                new PriceSelectionItem
                {
                    Id          = 2,
                    DisplayName = "1000 to 2000",
                    MinPrice    = 1000,
                    MaxPrice    = 2000
                },
                new PriceSelectionItem
                {
                    Id          = 3,
                    DisplayName = "Enter Price Range",
                    MinPrice    = -1,
                    MaxPrice    = -1
                }
                };

            prodModel.FilterViewModel.RatingSelection.RatingSelectionItems
                = new List <RatingSelectionItem>
                {
                new RatingSelectionItem
                {
                    Id          = 1,
                    DisplayName = "Average Rating: 5",
                    MinRating   = 5
                },
                new RatingSelectionItem
                {
                    Id          = 2,
                    DisplayName = "Average Rating: 4 and above",
                    MinRating   = 4
                },
                new RatingSelectionItem
                {
                    Id          = 3,
                    DisplayName = "Average Rating: 3 and above",
                    MinRating   = 3
                },
                new RatingSelectionItem
                {
                    Id          = 4,
                    DisplayName = "Average Rating: 2 and above",
                    MinRating   = 2
                },
                new RatingSelectionItem
                {
                    Id          = 5,
                    DisplayName = "Average Rating: 1 and above",
                    MinRating   = 1
                }
                };

            prodModel.FilterViewModel.NewestArrivalSelection.NewestArrivalSelectionItems
                = new List <NewestArrivalSelectionItem>
                {
                new NewestArrivalSelectionItem
                {
                    Id          = 1,
                    DisplayName = "Last 30 days",
                    AllowedDays = 30
                },
                new NewestArrivalSelectionItem
                {
                    Id          = 2,
                    DisplayName = "Last 60 days",
                    AllowedDays = 60
                },
                new NewestArrivalSelectionItem
                {
                    Id          = 3,
                    DisplayName = "Older",
                    AllowedDays = int.MaxValue
                }
                };

            prodModel.FilterViewModel.AvailabilitySelection.AvailabilitySelectionItems
                = new List <AvailabilitySelectionItem>
                {
                new AvailabilitySelectionItem
                {
                    Id          = 1,
                    DisplayName = "Only In Stock",
                    Value       = false
                },
                new AvailabilitySelectionItem
                {
                    Id          = 2,
                    DisplayName = "All Products",
                    Value       = true
                }
                };

            return(PartialView(prodModel));
        }
Пример #5
0
        public ActionResult Products(int?storeId, int?catId, [Form] ShopFilteringOptions filteringOptions,
                                     [Form] SelectedFilters selectedFilters,
                                     [Form] QueryOptions queryOptions,
                                     string searchQuery = null, bool flag1 = false, bool isKLId = false)
        {
            if (queryOptions == null)
            {
                queryOptions = new QueryOptions();
            }

            TempData["storeId"] = storeId;
            TempData["catId"]   = catId;
            bool?recFlag = TempData["flag"] as bool?;

            if (recFlag != null && recFlag == true)
            {
                TempData["flag"] = null;
                return(RedirectToAction("Products", new { storeId, catId, queryOptions }));
            }
            else if (TempData["AddedToCart"] is bool flag && flag)
            {
                TempData["flag"] = flag;
            }
            ViewBag.Flag = TempData["AddedToCart"] as bool?;

            Category parent = null;
            Dictionary <string, int> parentList = new Dictionary <string, int>();
            List <int>         catProdIds       = null;
            List <KL_Category> klCategories     = new List <KL_Category>();

            if (isKLId)
            {
                List <Category> categories = null;

                klCategories = db.KL_Categories
                               .Where(m => m.KL_CategoryId == catId)
                               .ToList();

                var parentCat = db.KL_Categories.FirstOrDefault(m => m.Id == catId);

                var klCatQueue = new Queue <KL_Category>();
                klCatQueue.Enqueue(parentCat);

                catProdIds = new List <int>();
                while (klCatQueue.Count > 0 && klCatQueue.Dequeue() is KL_Category kl_category)
                {
                    categories = db.Categories
                                 .Where(m => m.KL_CategoryId == kl_category.Id)
                                 .ToList();

                    foreach (var cat in categories)
                    {
                        var stocks = db.Stocks
                                     .Include(m => m.Product)
                                     .Where(m => m.Product.CategoryId == cat.Id)
                                     .Select(m => m.Id)
                                     .ToList();

                        catProdIds = catProdIds.Concat(stocks).ToList();
                    }

                    foreach (var kl_cat in db.KL_Categories
                             .Where(m => m.KL_CategoryId == kl_category.Id)
                             .ToList())
                    {
                        klCatQueue.Enqueue(kl_cat);
                    }
                }
                if (catProdIds.Count == 0)
                {
                    ViewBag.EmptyMessage = "No products available";
                }
            }
            else
            {
                parent = db.Categories.FirstOrDefault(m => m.Id == (catId ?? 0));
                while (parent != null)
                {
                    parentList.Add(parent.Name, parent.Id);
                    parent = db.Categories.FirstOrDefault(m => m.Id == parent.CategoryId);
                }
                catProdIds = db.Products.Where(m => m.CategoryId == (catId ?? m.CategoryId))
                             .Select(m => m.Id).ToList();
            }

            var store = db.Stores.FirstOrDefault(m => m.Id == (storeId ?? 0));

            var  thresholdDate = DateTime.Now;
            bool dateFlag      = false;

            if (filteringOptions.Allowed_Days == -1)
            {
                dateFlag = true;
            }
            else
            {
                thresholdDate = thresholdDate.AddDays(-1 * filteringOptions.Allowed_Days);
            }

            SearchParam search = null;

            if (!string.IsNullOrEmpty(searchQuery))
            {
                var stocks = db.Stocks
                             .Include(m => m.Product)
                             .Where(m => m.Product.Name.ToUpper().Contains(searchQuery.ToUpper()))
                             .OrderBy(m => m.Product.Name)
                             .Select(m => m.Id)
                             .Distinct()
                             .ToArray();

                var categories = db.Categories
                                 .Where(m => m.Name.ToUpper().Contains(searchQuery.ToUpper()))
                                 .OrderBy(m => m.Name)
                                 .Select(m => m.Id)
                                 .Distinct()
                                 .ToArray();

                TempData["Search"] = searchQuery;

                search = new SearchParam {
                    Categories = categories,
                    Stocks     = stocks
                };
            }

            var model = new ShopProductsViewModel
            {
                CategoryId    = catId,
                IsKlCat       = isKLId,
                KL_Categories = klCategories,
                Stocks        = (search == null || (search.Categories == null && search.Stocks == null)) ?
                                db.Stocks
                                .Include(m => m.Product)
                                .Where(m => m.StoreId == (storeId ?? m.StoreId) &&
                                       catProdIds.Contains(m.ProductId) &&
                                       m.Price >= filteringOptions.Price_MinValue &&
                                       m.Price <= filteringOptions.Price_MaxValue &&
                                       m.Product.Rating >= filteringOptions.Rating_Min &&
                                       m.Product.IsActive == true &&
                                       (filteringOptions.Availability || m.Status == StockStatus.InStock))
                                .OrderBy(queryOptions.Sort)
                                .ToList()
                         :
                                new List <Stock>(),
                Max       = new Dictionary <int, int>(),
                Breadcrum = (store != null && parent != null) ? new Dictionary <string, int>()
                                                                : null,
                SelectedOption   = queryOptions.SortOption,
                StoreId          = storeId,
                FilteringOptions = filteringOptions,
                CurrencySymbol   = (store != null) ? store.DefaultCurrencyType : "Rs."
            };

            if (search != null)
            {
                if (search.Categories != null && search.Categories.Count() > 0)
                {
                    model.Stocks = db.Stocks
                                   .Include(m => m.Product)
                                   .Where(m => search.Categories.Contains(m.Product.CategoryId) &&
                                          m.Price >= filteringOptions.Price_MinValue &&
                                          m.Price <= filteringOptions.Price_MaxValue &&
                                          m.Product.Rating >= filteringOptions.Rating_Min &&
                                          m.Product.IsActive == true &&
                                          (filteringOptions.Availability || m.Status == StockStatus.InStock))
                                   .OrderBy(queryOptions.Sort)
                                   .ToList();
                }

                if (search.Stocks != null && search.Stocks.Count() > 0)
                {
                    model.Stocks = model.Stocks.Concat(db.Stocks
                                                       .Include(m => m.Product)
                                                       .Where(m => search.Stocks.Contains(m.Id) &&
                                                              m.Price >= filteringOptions.Price_MinValue &&
                                                              m.Price <= filteringOptions.Price_MaxValue &&
                                                              m.Product.Rating >= filteringOptions.Rating_Min &&
                                                              m.Product.IsActive == true &&
                                                              (filteringOptions.Availability || m.Status == StockStatus.InStock))
                                                       .OrderBy(queryOptions.Sort)
                                                       .ToList()).ToList();
                }
            }

            var stockList = model.Stocks ?? new List <Stock>();

            foreach (var stock in stockList)
            {
                if (!dateFlag && (stock.StockingDate - thresholdDate).Days < 0)
                {
                    model.Stocks.Remove(stock);
                }
            }

            if (queryOptions.Sort == "Id ASC")
            {
                model.Stocks.Sort();
            }

            if (model.Breadcrum != null)
            {
                model.Breadcrum.Add(store.Name, store.Id);

                var keys = parentList.Keys.ToList();
                keys.Reverse();
                foreach (var key in keys)
                {
                    model.Breadcrum.Add(key, parentList[key]);
                }
            }

            var cart = GetCart();

            foreach (var stk in model.Stocks ?? new List <Stock>())
            {
                var available = 0;
                if (stk.MaxAmtPerUser < stk.CurrentStock)
                {
                    available = stk.MaxAmtPerUser;
                }
                else
                {
                    available = stk.CurrentStock;
                }
                var cartItm = cart.CartItems
                              .FirstOrDefault(m => m.StockId == stk.Id && m.IsEditable);
                if (cartItm != null)
                {
                    model.Max.Add(stk.Id, available - cartItm.Qty);
                }
                else
                {
                    model.Max.Add(stk.Id, available);
                }
            }
            if (model.FilterViewModel == null)
            {
                model.FilterViewModel = new ShopFilterViewModel {
                    PriceSelection         = new PriceSelection(),
                    RatingSelection        = new RatingSelection(),
                    NewestArrivalSelection = new NewestArrivalSelection(),
                    AvailabilitySelection  = new AvailabilitySelection()
                };
            }

            model.FilterViewModel.PriceSelection.PriceItemSelected   = selectedFilters.PriceFilterSelected;
            model.FilterViewModel.RatingSelection.RatingItemSelected = selectedFilters.RatingFilterSelected;
            model.FilterViewModel.NewestArrivalSelection.NewestArrivalItemSelected = selectedFilters.NewArrivalFilterSelected;
            model.FilterViewModel.AvailabilitySelection.AvailabilityItemSelected   = selectedFilters.AvailabilityFilterSelected;
            model.FilterViewModel.MinValue = filteringOptions.Price_MinValue;
            model.FilterViewModel.MaxValue = filteringOptions.Price_MaxValue;

            return(View(model));
        }
Пример #6
0
        public ActionResult FiltersPartialPost(ShopProductsViewModel model)
        {
            var priceOption        = Request.Form["PriceList"];
            var ratingOption       = Request.Form["RatingList"];
            var newArrivalsOption  = Request.Form["NewArrivalsList"];
            var availabilityOption = Request.Form["AvailabilityList"];

            var options         = new ShopFilteringOptions();
            var selectedOptions = new SelectedFilters();

            if (priceOption != null)
            {
                switch (priceOption)
                {
                case "1":
                {
                    options.Price_MaxValue = 1000;
                    break;
                }

                case "2":
                {
                    options.Price_MinValue = 1000;
                    options.Price_MaxValue = 2000;
                    break;
                }

                case "3":
                {
                    if (model.FilterViewModel.MinValue > 0 && model.FilterViewModel.MaxValue > 0)
                    {
                        options.Price_MaxValue = model.FilterViewModel.MaxValue;
                        options.Price_MinValue = model.FilterViewModel.MinValue;
                    }
                    break;
                }
                }
            }
            else
            {
                priceOption = "0";
            }

            if (ratingOption != null)
            {
                switch (ratingOption)
                {
                case "1":
                {
                    options.Rating_Min = 5;
                    break;
                }

                case "2":
                {
                    options.Rating_Min = 4;
                    break;
                }

                case "3":
                {
                    options.Rating_Min = 3;
                    break;
                }

                case "4":
                {
                    options.Rating_Min = 2;
                    break;
                }

                case "5":
                {
                    options.Rating_Min = 1;
                    break;
                }
                }
            }
            else
            {
                ratingOption = "0";
            }

            if (newArrivalsOption != null)
            {
                switch (newArrivalsOption)
                {
                case "1":
                {
                    options.Allowed_Days = 30;
                    break;
                }

                case "2":
                {
                    options.Allowed_Days = 60;
                    break;
                }

                case "3":
                {
                    break;
                }
                }
            }
            else
            {
                newArrivalsOption = "0";
            }

            if (availabilityOption != null)
            {
                switch (availabilityOption)
                {
                case "1":
                {
                    options.Availability = false;
                    break;
                }

                case "2":
                {
                    options.Availability = true;
                    break;
                }
                }
            }
            else
            {
                availabilityOption = "0";
            }
            selectedOptions.PriceFilterSelected        = int.Parse(priceOption);
            selectedOptions.RatingFilterSelected       = int.Parse(ratingOption);
            selectedOptions.NewArrivalFilterSelected   = int.Parse(newArrivalsOption);
            selectedOptions.AvailabilityFilterSelected = int.Parse(availabilityOption);
            return(RedirectToAction("Products", new { storeId = (model.CategoryId == null) ?
                                                                null as int?    :
                                                                db.Categories
                                                                .FirstOrDefault(m => m.Id == model.CategoryId)
                                                                .StoreId,
                                                      catId = model.CategoryId,
                                                      options.Price_MinValue, options.Price_MaxValue,
                                                      options.Rating_Min, options.Allowed_Days,
                                                      options.Availability,
                                                      selectedOptions.PriceFilterSelected,
                                                      selectedOptions.RatingFilterSelected,
                                                      selectedOptions.NewArrivalFilterSelected,
                                                      selectedOptions.AvailabilityFilterSelected,
                                                      SortOption = model.SelectedOption }));
        }
Пример #7
0
        public ActionResult ShopProducts(int id)
        {
            ShopProductsViewModel shopProductsViewModel = shopRepository.GetShopProducts(id);

            return(View("ShopProducts", shopProductsViewModel));
        }