public ViewResult List(string category, int page = 1) { var model = new MenuListViewModel { MenuItems = _baseDataAccess.GetMenuItems() .Where(m => category == null || m.Category.Name == category) .OrderBy(m => m.Id) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo() { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null? _baseDataAccess.GetMenuItems().Count() : _baseDataAccess.GetMenuItems().Count(e => e.Category.Name == category) }, CurrentCategory = category }; ViewBag.SelectedCategory = category; return(View(model)); }
public RedirectToRouteResult AddToCart(Cart cart, int id, string returnUrl) { var menuItem = _baseDataAccess.GetMenuItems() .FirstOrDefault(m => m.Id == id); if (menuItem == null) { throw new ArgumentException("There is no item with this id"); } cart.AddItem(menuItem, 1); return(RedirectToAction("Index", new { returnUrl })); }
public void AddToCart_add_to_empty_card() { //Arrange InitializeMenuItemsInBaseDataAccess(); InitializeEmptyCart(); var controller = GetControllerInstance(); var idAddingMenuItem = _baseDataAccess.GetMenuItems().First().Id; //Act var resultRedirect = controller.AddToCart(_cart, idAddingMenuItem, SampleReturnUrl); //Assert Assert.AreEqual(_menuItemsInCart.Count(), 1); Assert.IsNotNull(resultRedirect); Assert.AreEqual("", resultRedirect.RouteName); }
// // GET: /Nav/ public PartialViewResult Menu(string category = null) { ViewBag.SelectedCategory = category; IEnumerable <string> categories = _baseDataAccess.GetMenuItems() .Select(x => x.Category.Name) .Distinct() .OrderBy(x => x); return(PartialView(categories)); }