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) ) }); }
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))); }
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); }
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(); }