Ejemplo n.º 1
0
        public MenuViewModel Create(SerializedMenu serializedMenu)
        {
            IEnumerable <SerializedMenuItem> serializedMenuItems = new SerializedMenuItem[] { };

            if (!string.IsNullOrEmpty(serializedMenu.SerializedMenuItems))
            {
                serializedMenuItems = JsonConvert.DeserializeObject <IEnumerable <SerializedMenuItem> >(serializedMenu.SerializedMenuItems);
            }

            return(new MenuViewModel()
            {
                MenuItems = serializedMenuItems.OrderBy(cmi => cmi.Position).Select(
                    smi => new MenuItemViewModelFactory(this.RequestHandler).Create(smi)
                    ).ToList()
            });
        }
        public MenuItemViewModel Create(SerializedMenuItem serializedMenuItem)
        {
            IEnumerable <SerializedMenuItem> cachedMenuItems = new SerializedMenuItem[] { };

            if (!string.IsNullOrEmpty(serializedMenuItem.SerializedMenuItems))
            {
                cachedMenuItems = JsonConvert.DeserializeObject <IEnumerable <SerializedMenuItem> >(serializedMenuItem.SerializedMenuItems);
            }

            return(new MenuItemViewModel()
            {
                Name = serializedMenuItem.Name,
                Url = GlobalizedUrlFormatter.Format(this.RequestHandler.Storage, serializedMenuItem.Url),
                MenuItems = cachedMenuItems.OrderBy(cmi => cmi.Position).Select(
                    cmi => new MenuItemViewModelFactory(this.RequestHandler).Create(cmi)
                    )
            });
        }
Ejemplo n.º 3
0
        public MenuViewModel Create(SerializedMenu serializedMenu, string partialViewName, string additionalCssClass)
        {
            IEnumerable <SerializedMenuItem> serializedMenuItems = new SerializedMenuItem[] { };

            if (!string.IsNullOrEmpty(serializedMenu.SerializedMenuItems))
            {
                serializedMenuItems = JsonConvert.DeserializeObject <IEnumerable <SerializedMenuItem> >(serializedMenu.SerializedMenuItems);
            }

            return(new MenuViewModel()
            {
                MenuItems = serializedMenuItems.OrderBy(cmi => cmi.Position).Select(
                    smi => new MenuItemViewModelFactory(this.RequestHandler).Create(smi)
                    ).ToList(),
                PartialViewName = partialViewName ?? "_Menu",
                AdditionalCssClass = additionalCssClass
            });
        }
Ejemplo n.º 4
0
        private SerializedMenuItem SerializeMenuItem(Culture culture, MenuItem menuItem)
        {
            List <SerializedMenuItem> serializedChildMenuItems = new List <SerializedMenuItem>();

            foreach (MenuItem childMenuItem in this.requestHandler.Storage.GetRepository <IMenuItemRepository>().FilteredByMenuItemId(menuItem.Id).ToList())
            {
                serializedChildMenuItems.Add(this.SerializeMenuItem(culture, childMenuItem));
            }

            SerializedMenuItem serializedMenuItem = new SerializedMenuItem();

            serializedMenuItem.MenuItemId = menuItem.Id;
            serializedMenuItem.Name       = this.requestHandler.GetLocalizationValue(menuItem.NameId, culture.Id);
            serializedMenuItem.Url        = menuItem.Url;
            serializedMenuItem.Position   = menuItem.Position;

            if (serializedChildMenuItems.Count != 0)
            {
                serializedMenuItem.SerializedMenuItems = this.SerializeObject(serializedChildMenuItems);
            }

            return(serializedMenuItem);
        }