Example #1
0
        public dynamic SettingsShape(IUser user, int wishListId = 0)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            //build the settings shape for each wishlist
            var settingsShapes = new List <dynamic>();
            var wishlists      = _wishListServices.GetWishLists(user);

            foreach (var ext in _wishListExtensionProviders)
            {
                settingsShapes.Add(ext.BuildSettingsShape(wishlists));
            }

            return(_shapeFactory.WishListsSettings(
                       WishLists: wishlists,
                       WishListId: wishListId,
                       SettingsShapes: settingsShapes
                       ));
        }
Example #2
0
        protected override DriverResult Display(WishListListPart part, string displayType, dynamic shapeHelper)
        {
            var shapes = new List <DriverResult>(3);
            var user   = part.ContentItem.As <CommonPart>().Owner;
            //get the elements out of the wishlist
            List <dynamic> elementsShapes = new List <dynamic>();

            foreach (var wlItem in part.WishListItems)
            {
                var itemPart = wlItem.As <WishListItemPart>();
                if (itemPart != null)
                {
                    elementsShapes.Add(_contentManager.BuildDisplay(itemPart));
                }
            }
            //Get the additional shapes form the extensions
            List <dynamic> extensionsShapes = new List <dynamic>();

            foreach (var ext in _wishListExtensionProviders)
            {
                extensionsShapes.Add(ext.BuildWishListDisplayShape(part));
            }

            shapes.Add(ContentShape("Parts_WishListList", () =>
                                    shapeHelper.Parts_WishListList(new WishListListViewModel {
                ElementsShapes  = elementsShapes,
                ExtensionShapes = extensionsShapes
            })));
            shapes.Add(ContentShape("Parts_ListOfWishLists", () =>
                                    shapeHelper.Parts_ListOfWishLists(
                                        WishLists: _wishListServices.GetWishLists(user)
                                        )));
            shapes.Add(ContentShape("Parts_WishListsActions", () =>
                                    shapeHelper.Parts_WishListsActions(
                                        CreateShape: _wishListsUIServices.CreateShape(user),
                                        SettingsShape: _wishListsUIServices.SettingsShape(user, part.ContentItem.Id)
                                        )));

            return(Combined(shapes.ToArray()));
        }
        protected override DriverResult Display(ProductPart part, string displayType, dynamic shapeHelper)
        {
            var user = _wca.GetContext().CurrentUser;
            //usually, wishlists only apply to authenticated users.
            //however, we are still going to show the "Add to list" functionalities, to drive sign-up / login
            var wishLists = user == null ?
                            new List <WishListListPart>() :
                            _wishListServices.GetWishLists(user).ToList();

            // Get attributes and add them to the add to list shape
            var attributeShapes = _attributeDrivers
                                  .Select(p => p.GetAttributeDisplayShape(part.ContentItem, shapeHelper))
                                  .ToList();

            return(ContentShape("Parts_Product_AddToWishlistButton", () =>
                                shapeHelper.Parts_Product_AddToWishlistButton(
                                    ProductId: part.Id,
                                    User: user,
                                    WishLists: wishLists,
                                    Prefix: Prefix,
                                    CreateShape: _wishListsUIServices.CreateShape(user, part), //in case we want a "new wishlist" link
                                    AttributeShapes: attributeShapes
                                    )));
        }
Example #4
0
        public ActionResult UpdateSettings(
            int wishListId, int defaultId,
            IDictionary <int, string> newTitles, IEnumerable <int> wishListsToDelete)
        {
            var user = _wca.GetContext().CurrentUser;

            var wishLists = _wishListServices.GetWishLists(user);

            foreach (var wishList in wishLists)
            {
                //these are the wishlists for the current user, so we don't need to evaluate their permissions
                var wlId = wishList.ContentItem.Id;
                if (wishListsToDelete?.Contains(wlId) == true)
                {
                    //Delete this list
                    _wishListServices.DeleteWishlist(wishList);
                }
                else
                {
                    //2. Update titles
                    var title = newTitles[wlId];
                    wishList.ContentItem.As <TitlePart>().Title = title;
                    //3. Update default wishlist
                    wishList.IsDefault = wlId == defaultId;
                    //4. Process extension behaviours
                    foreach (var ext in _wishListExtensionProviders)
                    {
                        ext.UpdateSettings(user, wishList);
                    }
                }
            }
            //we may have deleted the default wishlist
            //that condition is handled in the GetDefaultWishList method

            return(RedirectToAction("Index", new { id = wishListId }));
        }