예제 #1
0
        public ActionResult Index(string category, string subCategory, int?minPrice, int?maxPrice, string search, string pageSize, int?currentPage)
        {
            var StoreService = new StoreService();


            var PageSize = pageSize != null?Convert.ToInt32(pageSize) : 30;

            var Deleted = "Deleted Toy";
            List <Categories> CategoryList = db.Categories.ToList();
            var MaxPrice = maxPrice ?? (from ToysTable in db.Toy select ToysTable.Price).Max();
            var MinPrice = minPrice ?? 0;


            var Toys = StoreService.GetProducts(category, subCategory, minPrice, maxPrice, search);

            BrowsePartial data = new BrowsePartial
            {
                SelectedCategory    = category ?? null,
                SelectedSubCategory = subCategory ?? null,

                MinPrice = MinPrice,
                MaxPrice = (int)Math.Ceiling(MaxPrice),
                Search   = search ?? null,
                PageSize = PageSize,

                Categories    = CategoryList,
                Toys          = Toys.Where(t => t.ToysName != Deleted).ToPagedList(currentPage ?? 1, PageSize),
                SubCategories = (category != null) ? (db.Categories.Include("Toy").Single(c => c.CategoryName == category).SubCategories).ToList() : null,
            };

            return(View(data));
        }
예제 #2
0
        public ActionResult IndexR(string search, int?P, int PS)
        {
            List <Categories> CL   = db.Categories.ToList();
            List <Toy>        Toys = db.Toy.ToList();

            if (search != "" | search != null)
            {
                Toys = db.Toy.Where(x => x.ToysName.Contains(search)).ToList();
            }
            BrowsePartial a = new BrowsePartial
            {
                C  = CL,
                T  = Toys.ToPagedList(P ?? 1, PS),
                SC = null,
                PC = null,
            };

            return(View(a));
        }
예제 #3
0
        public ActionResult Index(string C, string SC, int?PC, int?P, string search, string ps)
        {
            //var PS = 3;
            var PS               = 30;
            var Deleted          = "Deleted Toy";
            List <Categories> CL = db.Categories.ToList();

            //functie schrijven die prijs category als parameter krijgt en de prijsrange terug geeft om code te verminderen

            if (C != null)
            {
                ViewBag.Category     = C;
                ViewData["Category"] = C;
            }
            if (SC != null)
            {
                ViewBag.SubCategory     = SC;
                ViewData["SubCategory"] = SC;
            }
            if (PC != null)
            {
                ViewBag.PriceCategory     = PC;
                ViewData["PriceCategory"] = PC;
            }
            if (P != null)
            {
                ViewBag.Page     = P;
                ViewData["Page"] = P;
            }
            if (search != null)
            {
                ViewBag.srch     = search;
                ViewData["srch"] = search;
            }
            if (ps != null)
            {
                PS                   = Convert.ToInt32(ps);
                ViewBag.PS           = Convert.ToInt32(ps);;
                ViewData["PageSize"] = Convert.ToInt32(ps);;
            }


            if (C != null && SC == null && PC == null && search == null)                //category page 2
            {
                Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category

                BrowsePartial a = new BrowsePartial
                {
                    C  = CL,
                    T  = OC.Toy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                    SC = OC.SubCategories,
                    PC = null
                };
                return(View(a));
            }


            else if (C != null && SC != null && PC == null && search == null)                      // subcategory page
            {
                Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                BrowsePartial a   = new BrowsePartial
                {
                    C  = CL,
                    T  = OSC.Toy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                    SC = OC.SubCategories,
                    PC = null
                };
                return(View(a));
            }


            else if (C != null && SC != null && PC != null && search == null) // price page naar subcategory filter
            {
                //ICollection<Toy> toy = null;

                if (PC == 1)
                {
                    var TTemp = from TT in db.Toy
                                where TT.SubCategories.SCName == SC && TT.Price > 0.00m && TT.Price < 10.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                    SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a   = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 2)
                {
                    var TTemp = from TT in db.Toy
                                where TT.SubCategories.SCName == SC && TT.Price > 9.99m && TT.Price < 20.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                    SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a   = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 3)
                {
                    var TTemp = from TT in db.Toy
                                where TT.SubCategories.SCName == SC && TT.Price > 19.99m && TT.Price < 50.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                    SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a   = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 4)
                {
                    var TTemp = from TT in db.Toy
                                where TT.SubCategories.SCName == SC && TT.Price > 49.99m && TT.Price < 100.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                    SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a   = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 5)
                {
                    var TTemp = from TT in db.Toy
                                where TT.SubCategories.SCName == SC && TT.Price > 99.99m && TT.Price < 500.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                    SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a   = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 6)
                {
                    var TTemp = from TT in db.Toy
                                where TT.SubCategories.SCName == SC && TT.Price > 500.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories    OC  = db.Categories.Include("Toy").Single(c => c.CName == C);        //One Category
                    SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a   = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else
                {
                    return(View());
                }
            } //X


            else if (C != null && SC == null && PC != null && search == null) // price page naar category filter
            {
                //ICollection<Toy> toy = null;

                if (PC == 1)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Categories.CName == C && TT.Price > 0.00m && TT.Price < 10.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 2)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Categories.CName == C && TT.Price > 9.99m && TT.Price < 20.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 3)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Categories.CName == C && TT.Price > 19.99m && TT.Price < 50.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 4)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Categories.CName == C && TT.Price > 49.99m && TT.Price < 100.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 5)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Categories.CName == C && TT.Price > 99.99m && TT.Price < 500.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 6)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Categories.CName == C && TT.Price > 500.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = OC.SubCategories,
                        PC = null
                    };
                    return(View(a));
                }
                else
                {
                    return(View());
                }
            } //X


            else if (C == null && SC == null && PC != null && search == null) // price page naar category filter
            {
                //ICollection<Toy> toy = null;

                if (PC == 1)
                {
                    var TTemp = from TT in db.Toy
                                where  TT.Price > 0.00m && TT.Price < 10.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();

                    //Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = null,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 2)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Price > 9.99m && TT.Price < 20.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    //Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = null,
                        PC = null
                    };
                    return(View(a));


                    //var TTemp = from TT in db.Toy
                    //            where TT.Categories.CName == C && TT.Price > 9.99m && TT.Price < 20.00m
                    //            select TT;
                    //var TToy = new List<Toy>();
                    //foreach (Toy t in TTemp)
                    //{
                    //    TToy.Add(t);
                    //}


                    ////var TToy = TTemp.First();
                    ////Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    ////SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    //BrowsePartial a = new BrowsePartial
                    //{
                    //    C = CL,
                    //    T = TToy,
                    //    SC = null,
                    //    PC = null
                    //};
                    //return View(a);
                }
                else if (PC == 3)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Price > 19.99m && TT.Price < 50.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    //Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = null,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 4)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Price > 49.99m && TT.Price < 100.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    //Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = null,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 5)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Price > 99.99m && TT.Price < 500.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    //Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = null,
                        PC = null
                    };
                    return(View(a));
                }
                else if (PC == 6)
                {
                    var TTemp = from TT in db.Toy
                                where TT.Price > 500.00m
                                select TT;
                    var TToy = new List <Toy>();
                    foreach (Toy t in TTemp)
                    {
                        TToy.Add(t);
                    }


                    //var TToy = TTemp.First();
                    //Categories OC = db.Categories.Include("Toy").Single(c => c.CName == C); //One Category
                    //SubCategories OSC = db.SubCategories.Include("Toy").Single(sc => sc.SCName == SC); //One SubCategory
                    BrowsePartial a = new BrowsePartial
                    {
                        C  = CL,
                        T  = TToy.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                        SC = null,
                        PC = null
                    };
                    return(View(a));
                }
                else
                {
                    return(View());
                }
            } //X

            else if (C == null && SC == null && PC == null && search != null) //start page
            {
                List <Toy> Toys = db.Toy.ToList();

                var TST = db.Toy.Where(x => x.ToysName.Contains(search)).ToList();

                BrowsePartial a = new BrowsePartial
                {
                    C  = CL,
                    T  = TST.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                    SC = null,
                    PC = null,
                };
                return(View(a));
            }

            else //start page
            {
                List <Toy>    Toys = db.Toy.ToList();
                BrowsePartial a    = new BrowsePartial
                {
                    C  = CL,
                    T  = Toys.Where(t => t.ToysName != Deleted).ToPagedList(P ?? 1, PS),
                    SC = null,
                    PC = null,
                };
                return(View(a));
            }
        }