public RedirectToActionResult AddToShoppingCart(int accessoryId) { var selectedAccessory = _accessoryRepository.GetAccessories().FirstOrDefault(p => p.AccessoryId == accessoryId); if (selectedAccessory != null) { _shoppingCart.AddToCart(selectedAccessory, 1); } return(RedirectToAction("Index")); }
public IActionResult Index(string category) { IEnumerable <Accessory> accessories; if (string.IsNullOrEmpty(category)) { accessories = _accessoryRepository.GetAccessories(); } else { accessories = _accessoryRepository.GetAccessories().Where(a => a.Category.CategoryName == category).OrderBy(a => a.Name); } return(View(accessories)); }
public IActionResult LoadMoreAccessories(int pageIndex, int pageSize) { IEnumerable <Accessory> dbAccessories = null; dbAccessories = _accessoryRepository.GetAccessories().OrderBy(a => a.AccessoryId).Skip(pageIndex * pageSize).Take(pageSize); List <AccessoryVM> accessories = new List <AccessoryVM>(); foreach (var dbAccessory in dbAccessories) { accessories.Add(MapDbAccessoryTAccessoryViewModel(dbAccessory)); } return(Ok(accessories)); }