Ejemplo n.º 1
0
        public void OnGet()
        {
            CurrentMenu = Menu.FullMenu();

            IEnumerable <IOrderItem> CurDescriptionMenu = Menu.FullMenu();



            //Filter by term
            if (SearchTerms != null)
            {
                foreach (string d in SearchTerms.Split(' '))
                {
                    foreach (IOrderItem item in CurrentMenu)
                    {
                        CurDescriptionMenu = CurDescriptionMenu.Where(item => item.Description.ToLower().Contains(d.ToLower()));

                        CurrentMenu = CurrentMenu.Where(item => item.ToString().ToLower().Contains(SearchTerms.ToLower()) || item.Description.ToLower().Contains(d.ToLower()));
                    }
                    foreach (IOrderItem curitem in CurDescriptionMenu)
                    {
                        CurrentMenu.Append(curitem);
                    }
                }
            }



            //Filter by calories
            if (CalMin != null || CalMax != null)
            {
                foreach (IOrderItem item in CurrentMenu)
                {
                    CurrentMenu = CurrentMenu.Where(item => (CalMin != null && item.Calories >= CalMin) || (CalMax != null && item.Calories <= CalMax));

                    if (CalMax != null && CalMin != null)
                    {
                        CurrentMenu = CurrentMenu.Where(item => item.Calories >= CalMin && item.Calories <= CalMax);
                    }
                }
            }

            //filter by price
            if (PriceMin != null || PriceMax != null)
            {
                foreach (IOrderItem item in CurrentMenu)
                {
                    CurrentMenu = CurrentMenu.Where(item => (PriceMin != null && item.Price >= PriceMin) || (PriceMax != null && item.Price <= PriceMax));

                    if (PriceMax != null && PriceMin != null)
                    {
                        CurrentMenu = CurrentMenu.Where(item => item.Price >= PriceMin && item.Price <= PriceMax);
                    }
                }
            }

            //filter by category
            if (Category.Count() != 0)
            {
                foreach (IOrderItem item in CurrentMenu)
                {
                    CurrentMenu = CurrentMenu.Where(item => (item is Entree && Category.Contains("Entrees")) || (Category.Contains("Sides") && item is Side) || (Category.Contains("Drinks") && item is Drink));
                }
            }
        }
Ejemplo n.º 2
0
        public void OnGet()
        {
            SearchTerms = Request.Query["SearchTerms"];
            Types       = Request.Query["Types"];
            string pmin = Request.Query["PriceMin"];
            string pmax = Request.Query["PriceMax"];
            string cmin = Request.Query["CalMin"];
            string cmax = Request.Query["CalMax"];

            if (!String.IsNullOrEmpty(pmin))
            {
                PriceMin = double.Parse(pmin);
            }
            if (!String.IsNullOrEmpty(pmax))
            {
                PriceMax = double.Parse(pmax);
            }

            if (!String.IsNullOrEmpty(cmin))
            {
                CalMin = uint.Parse(cmin);
            }
            if (!String.IsNullOrEmpty(cmax))
            {
                CalMax = uint.Parse(cmax);
            }

            if (!String.IsNullOrEmpty(SearchTerms))
            {
                SearchTermArray = SearchTerms.ToLower().Split(' ');
            }

            Menus = Menu.FullMenu();
            //Filter by SearchTerms
            if (SearchTermArray != null && SearchTermArray.Length != 0)
            {
                Menus = Menus.Where(IOrderItem => SearchTermArray.Any(IOrderItem.ToString().ToLower().Contains) || SearchTermArray.Any(IOrderItem.Description.ToLower().Contains));
            }



            //Menus = Menu.FilterByType(Menus,Types);
            //Filter by type
            if (Types != null && Types.Length != 0)
            {
                if (!(Types.Contains("Entree")))
                {
                    Menus = Menus.Where(IOrderItem => !(IOrderItem is Entree));
                }
                if (!(Types.Contains("Side")))
                {
                    Menus = Menus.Where(IOrderItem => !(IOrderItem is Side));
                }
                if (!(Types.Contains("Drink")))
                {
                    Menus = Menus.Where(IOrderItem => !(IOrderItem is Drink));
                }
            }



            //Menus = Menu.FilterByPrice(Menus, PriceMin, PriceMax);
            //Filter by Price
            Menus = Menus.Where(IOrderItem => IOrderItem.Price <= PriceMax && IOrderItem.Price >= PriceMin);
            //Menus = Menu.FilterByCal(Menus, CalMin, CalMax);
            //Folter by Calories
            Menus = Menus.Where(IOrderItem => IOrderItem.Calories <= CalMax && IOrderItem.Calories >= CalMin);
        }