/// <summary> /// Creates a <see cref="WishListModel"/>. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="WishListModel"/>. /// </returns> public WishListModel CreateWishList(RenderModel model) { if (_currentCustomer.IsAnonymous) { var badOperation = new InvalidOperationException("Wish lists cannot be created for anonymous customers"); LogHelper.Error <ViewModelFactory>("Attempted to create a wish list for an anonymous customer", badOperation); throw badOperation; } var viewModel = this.Build <WishListModel>(model); //// this is a protected page - so the customer has to be an ICustomer var customer = (ICustomer)viewModel.CurrentCustomer; var wishList = customer.WishList(); viewModel.WishListTable = new WishListTableModel() { Items = wishList.Items.Select(_basketLineItemFactory.Value.Build).ToArray(), Currency = viewModel.Currency, WishListPageId = BazaarContentHelper.GetWishListContent().Id, BasketPageId = BazaarContentHelper.GetBasketContent().Id, ContinueShoppingPage = BazaarContentHelper.GetContinueShoppingContent() }; return(viewModel); }
/// <summary> /// Creates a <see cref="BasketModel"/>. /// </summary> /// <param name="model"> /// The model. /// </param> /// <param name="basket"> /// The <see cref="IBasket"/> /// </param> /// <returns> /// The <see cref="BasketModel"/>. /// </returns> public BasketModel CreateBasket(RenderModel model, IBasket basket) { var viewModel = this.Build <BasketModel>(model); viewModel.BasketTable = new BasketTableModel { Items = basket.Items.Select(_basketLineItemFactory.Value.Build).ToArray(), TotalPrice = basket.Items.Sum(x => x.TotalPrice), Currency = viewModel.Currency, CheckoutPage = BazaarContentHelper.GetCheckoutPageContent(), ContinueShoppingPage = BazaarContentHelper.GetContinueShoppingContent(), ShowWishList = viewModel.ShowWishList && !_currentCustomer.IsAnonymous, WishListPageId = BazaarContentHelper.GetWishListContent().Id, BasketPageId = BazaarContentHelper.GetBasketContent().Id }; return(viewModel); }