public ViewResult ListAllShoppingBaskets() { var lineItemsGroupedByShoppingBasketID = from lineItem in this.repository.LineItems group lineItem by lineItem.ShoppingBasketID into lineItemGroup select lineItemGroup.Key; int[] shoppingBasketIDsToDisplay = lineItemsGroupedByShoppingBasketID.ToArray(); var lineItemsForTheseShoppingBaskets = from lineItem in this.repository.LineItems where shoppingBasketIDsToDisplay.Contains(lineItem.ShoppingBasketID) select new LineItemModel { ShoppingBasketID = lineItem.ShoppingBasketID, Quantity = lineItem.Quantity, Name = lineItem.Name, Price = lineItem.Price, SalesTaxRate = lineItem.SalesTaxRate, ImportDutyRate = lineItem.ImportDutyRate }; List <LineItemModel> lineItemModelsToDisplay = lineItemsForTheseShoppingBaskets.ToList <LineItemModel>(); List <ShoppingBasketModel> ShoppingBaskets = new List <ShoppingBasketModel>(); for (int i = 0; i < shoppingBasketIDsToDisplay.Length; i++) { int tempShoppingBasketID = shoppingBasketIDsToDisplay[i]; List <LineItemModel> tempList = new List <LineItemModel>(); foreach (LineItemModel lim in lineItemModelsToDisplay) { if (lim.ShoppingBasketID == tempShoppingBasketID) { tempList.Add(lim); } } ShoppingBasketModel addThisShoppingBasketModel = new ShoppingBasketModel(tempShoppingBasketID, tempList); ShoppingBaskets.Add(addThisShoppingBasketModel); } Session["ShoppingBaskets"] = ShoppingBaskets; return(View(new ShoppingBasketOutputViewModel { ShoppingBaskets = ShoppingBaskets, })); }
public ActionResult Index() { ShoppingBasketCollectionModel model = new ShoppingBasketCollectionModel(); model.ShoppingBasketItems = new List <ShoppingBasketModel>(); //get basket items for user BasketRepository br = new BasketRepository(); var user = UserManager.FindByEmail(this.User.Identity.Name); if (user != null) { userId = user.Id; model.IsLoggedIn = true; } else { userId = ""; model.IsLoggedIn = false; } var items = br.LoadByUserId(userId).ToList(); foreach (var item in items.Where(x => x.ArchiveDateUTC == null)) { var m = new ShoppingBasketModel(); m.Id = item.Id; m.Name = item.Name; m.Description = item.Description; m.Currency = item.Currency; m.Price = item.Price; m.Quantity = item.Quantity; m.Url = item.Url; model.ShoppingBasketItems.Add(m); } return(View(model)); }