コード例 #1
0
        public MenuViewModel Create(CachedMenu cachedMenu)
        {
            IEnumerable <CachedMenuItem> cachedMenuItems = new CachedMenuItem[] { };

            if (!string.IsNullOrEmpty(cachedMenu.CachedMenuItems))
            {
                cachedMenuItems = JsonConvert.DeserializeObject <IEnumerable <CachedMenuItem> >(cachedMenu.CachedMenuItems);
            }

            return(new MenuViewModel()
            {
                MenuItems = cachedMenuItems.OrderBy(cmi => cmi.Position).Select(
                    cmi => new MenuItemViewModelFactory(this.handler).Create(cmi)
                    )
            });
        }
コード例 #2
0
        public async Task <IViewComponentResult> InvokeAsync(string code)
        {
            CachedMenu cachedMenu = this.Storage.GetRepository <ICachedMenuRepository>().WithCultureIdAndCode(
                CultureManager.GetCurrentCulture(this.Storage).Id, code
                );

            if (cachedMenu == null)
            {
                Menu menu = this.Storage.GetRepository <IMenuRepository>().WithCode(code);

                if (menu == null)
                {
                    return(null);
                }

                return(this.View(new MenuViewModelFactory(this).Create(menu)));
            }

            return(this.View(new MenuViewModelFactory(this).Create(cachedMenu)));
        }
コード例 #3
0
        private CachedMenu CacheMenu(Culture culture, Menu menu)
        {
            List <CachedMenuItem> cachedMenuItems = new List <CachedMenuItem>();

            foreach (MenuItem menuItem in this.handler.Storage.GetRepository <IMenuItemRepository>().FilteredByMenuId(menu.Id))
            {
                cachedMenuItems.Add(this.CacheMenuItem(culture, menuItem));
            }

            CachedMenu cachedForm = new CachedMenu();

            cachedForm.MenuId    = menu.Id;
            cachedForm.CultureId = culture.Id;
            cachedForm.Code      = menu.Code;

            if (cachedMenuItems.Count != 0)
            {
                cachedForm.CachedMenuItems = this.SerializeObject(cachedMenuItems);
            }

            return(cachedForm);
        }
コード例 #4
0
        public void CacheMenu(Menu menu)
        {
            foreach (Culture culture in this.handler.Storage.GetRepository <ICultureRepository>().NotNeutral())
            {
                CachedMenu cachedMenu = this.handler.Storage.GetRepository <ICachedMenuRepository>().WithKey(culture.Id, menu.Id);

                if (cachedMenu == null)
                {
                    this.handler.Storage.GetRepository <ICachedMenuRepository>().Create(this.CacheMenu(culture, menu));
                }

                else
                {
                    CachedMenu temp = this.CacheMenu(culture, menu);

                    cachedMenu.Code            = temp.Code;
                    cachedMenu.CachedMenuItems = temp.CachedMenuItems;
                    this.handler.Storage.GetRepository <ICachedMenuRepository>().Edit(cachedMenu);
                }
            }

            this.handler.Storage.Save();
        }