private IViewComponentResult GetViewComponentResult(string code) { SerializedMenu serializedMenu = this.Storage.GetRepository <ISerializedMenuRepository>().WithCultureIdAndCode( CultureManager.GetCurrentCulture(this.Storage).Id, code ); if (serializedMenu == null) { return(this.Content($"There is no menu with code “{code}” defined.")); } return(this.View(new MenuViewModelFactory(this).Create(serializedMenu))); }
private IViewComponentResult GetViewComponentResult(string code, string partialViewName = null, string additionalCssClass = null) { SerializedMenu serializedMenu = this.Storage.GetRepository <ISerializedMenuRepository>().WithCultureIdAndCode( this.GetService <ICultureManager>().GetCurrentCulture().Id, code ); if (serializedMenu == null) { return(this.Content($"There is no menu with code “{code}” defined.")); } return(this.View(new MenuViewModelFactory(this).Create(serializedMenu, partialViewName, additionalCssClass))); }
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 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 }); }
public async Task <IViewComponentResult> InvokeAsync(string code) { SerializedMenu serializedMenu = this.Storage.GetRepository <ISerializedMenuRepository>().WithCultureIdAndCode( CultureManager.GetCurrentCulture(this.Storage).Id, code ); if (serializedMenu == 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(serializedMenu))); }
private SerializedMenu SerializeMenu(Culture culture, Menu menu) { List <SerializedMenuItem> serializedMenuItems = new List <SerializedMenuItem>(); foreach (MenuItem menuItem in this.requestHandler.Storage.GetRepository <IMenuItemRepository>().FilteredByMenuId(menu.Id).ToList()) { serializedMenuItems.Add(this.SerializeMenuItem(culture, menuItem)); } SerializedMenu serializedForm = new SerializedMenu(); serializedForm.MenuId = menu.Id; serializedForm.CultureId = culture.Id; serializedForm.Code = menu.Code; if (serializedMenuItems.Count != 0) { serializedForm.SerializedMenuItems = this.SerializeObject(serializedMenuItems); } return(serializedForm); }
public void SerializeMenu(Menu menu) { foreach (Culture culture in this.requestHandler.Storage.GetRepository <ICultureRepository>().NotNeutral().ToList()) { SerializedMenu serializedMenu = this.requestHandler.Storage.GetRepository <ISerializedMenuRepository>().WithKey(culture.Id, menu.Id); if (serializedMenu == null) { this.requestHandler.Storage.GetRepository <ISerializedMenuRepository>().Create(this.SerializeMenu(culture, menu)); } else { SerializedMenu temp = this.SerializeMenu(culture, menu); serializedMenu.Code = temp.Code; serializedMenu.SerializedMenuItems = temp.SerializedMenuItems; this.requestHandler.Storage.GetRepository <ISerializedMenuRepository>().Edit(serializedMenu); } } this.requestHandler.Storage.Save(); }