Example #1
0
        // GET: Restaurant
        public ActionResult Index(string SearchString, string sort)
        {
            List <Restaurant> allRestaurants = (List <Restaurant>)LibHelper.ShowAllRestaurants();

            ViewBag.SearchString = SearchString;
            if (!String.IsNullOrEmpty(SearchString))
            {
                return(View(sorter.SearchRestaurantByName(SearchString, allRestaurants)));
            }
            ViewBag.Top3         = sort == "Top3Rating" ? "sortTop3" : "Top3Rating";
            ViewBag.SortByRating = sort == "RatingsDescending" ? "ByRatings" : "RatingsDescending";
            ViewBag.SortByName   = sort == "NamesAscending" ? "ByNames" : "NamesAscending";

            if (sort == "Top3Rating")
            {
                return(View(sorter.SortByRating(3, allRestaurants)));
            }
            if (sort == "RatingsDescending")
            {
                return(View(sorter.SortByRating(allRestaurants)));
            }
            if (sort == "NamesAscending")
            {
                return(View(sorter.SortByNameAscending(allRestaurants)));
            }
            else
            {
                return(View(LibHelper.ShowAllRestaurants()));
            }
        }
Example #2
0
        public void SearchRestaurantByName_Test()
        {
            actualList = new List <Restaurant>();
            SortLogic sort = new SortLogic();

            actualList.Add(restaurant1);
            actualList.Add(restaurant2);
            actualList.Add(restaurant3);
            actualList.Add(restaurant4);
            Restaurant        actual       = actualList[0];
            List <Restaurant> expectedList = new List <Restaurant>();

            expectedList = (List <Restaurant>)sort.SearchRestaurantByName("M", actualList);
            Restaurant expected = expectedList[0];

            Assert.AreEqual(actual, expected, expected.RestaurantName + " " + actual.RestaurantName);
        }