public IList<Menu> List() { var options = new GetMenuOptions(); options.LoadRecipes = this.loadRecipes; var result = this.context.GetMenus(this.menusToLoad, options); return result; }
public Menu[] GetMenus(IList<Menu> menus, GetMenuOptions options) { throw new NotImplementedException(); }
/// <summary> /// Returns the specified set of menus owned by the current user. /// </summary> /// <param name="menus">One or more Menu objects. Use Menu.Favorites to load the default favorites menu.</param> /// <param name="options">Specifies what data to load.</param> /// <returns>An array of Menu objects with the specified data loaded.</returns> public virtual Menu[] GetMenus(IList<Menu> menus, GetMenuOptions options) { return this.Adapter.GetMenus(this.Identity, menus, options); }
public IList<Menu> List() { var options = new GetMenuOptions(); options.LoadRecipes = loadRecipes; return context.GetMenus(menusToLoad, options); }
public Menu[] GetMenus(AuthIdentity identity, IList<Menu> menus, GetMenuOptions options) { using (var session = GetSession()) { // menus will be null if all menus should be loaded, or a list of Menu objects to specify individual menus to load if (options == null) throw new ArgumentNullException("options"); if (identity == null) throw new ArgumentNullException("identity"); var loadFav = true; var query = session.QueryOver<Models.Menus>() .Where(p => p.UserId == identity.UserId); if (menus != null) // Load individual menus { loadFav = menus.Contains(Menu.Favorites); var ids = menus.Where(m => m.Id.HasValue).Select(m => m.Id.Value).ToArray(); query = query.AndRestrictionOn(p => p.MenuId).IsInG(ids); } var dbMenus = query.List(); var ret = new List<Menu>(); if (loadFav) ret.Add(Menu.Favorites); ret.AddRange(dbMenus.Select(m => m.AsMenu())); if (!options.LoadRecipes) // We're done! return ret.ToArray(); // Load recipes into each menu ICriterion filter = (loadFav ? Expression.Or(Expression.IsNull("Menu"), Expression.InG("Menu", dbMenus)) // Menu can be null, or in loaded menu list : Expression.InG("Menu", dbMenus)); // Menu must be in loaded menu list var dbFavorites = session.QueryOver<Favorites>() .Fetch(prop => prop.Recipe).Eager .Where(p => p.UserId == identity.UserId) .Where(filter) .List(); return ret.Select(m => new Menu(m) { Recipes = (m.Id.HasValue ? dbFavorites.Where(f => f.Menu != null && f.Menu.MenuId == m.Id) : dbFavorites.Where(f => f.Menu == null) ).Select(r => r.Recipe.AsRecipeBrief()).ToArray() }).ToArray(); } }
/// <summary> /// Returns the specified set of menus owned by the current user. /// </summary> /// <param name="menus">One or more Menu objects. Use Menu.Favorites to load the default favorites menu.</param> /// <param name="options">Specifies what data to load.</param> /// <returns>An array of Menu objects with the specified data loaded.</returns> public Menu[] GetMenus(IList<Menu> menus, GetMenuOptions options) { var loadFav = true; var query = store.Menus.Where(p => p.UserId == Identity.UserId); if (menus != null) // Load individual menus { loadFav = menus.Contains(Menu.Favorites); var ids = menus.Where(m => m.Id.HasValue).Select(m => m.Id.Value); query = query.Where(p => ids.Contains(p.MenuId)); } var dbMenus = query.ToList(); var ret = new List<Menu>(); if (loadFav) ret.Add(Menu.Favorites); ret.AddRange(dbMenus.Select(Data.DTO.Menus.ToMenu)); if (!options.hasLoadedRecipes) // We're done! return ret.ToArray(); var indexRecipes = store.GetIndexedRecipes(); var dbFavorites = store.Favorites.Where(p => p.UserId == Identity.UserId); return ret.Select(m => new Menu(m) { Recipes = (m.Id.HasValue ? dbFavorites.Where(f => f.MenuId.HasValue && f.MenuId == m.Id) : dbFavorites.Where(f => f.MenuId == null) ).Select(r => Data.DTO.Recipes.ToRecipeBrief(indexRecipes[r.RecipeId])).ToArray() }).ToArray(); }
public Menu[] GetMenus(AuthorIdentity identity, IList<Menu> menus, GetMenuOptions options) { using (var session = this.GetSession()) { // menus will be null if all menus should be loaded, or a list of Menu objects to specify individual menus to load if (options == null) { throw new ArgumentNullException("There are no menu options."); } if (identity == null) { throw new ArgumentNullException("There are no identities."); } var favouritesLoaded = true; var query = session.QueryOver<Menus>().Where(p => p.UserId == identity.UserId); if (menus != null) { favouritesLoaded = menus.Contains(Menu.Favorites); query = LoadIndividualMenus(menus, query); } var databaseMenus = query.List(); var favouriteMenus = new List<Menu>(); if (favouritesLoaded) { favouriteMenus.Add(Menu.Favorites); } favouriteMenus.AddRange(databaseMenus.Select(m => m.AsMenu())); if (!options.LoadRecipes) { return favouriteMenus.ToArray(); } var favorites = LoadRecipesInEachMenu(identity, favouritesLoaded, databaseMenus, session); return favouriteMenus.Select( m => new Menu(m) { Recipes = (m.Id.HasValue ? favorites.Where(f => f.Menu != null && f.Menu.MenuId == m.Id) : favorites.Where(f => f.Menu == null)).Select( r => r.Recipe.AsRecipeBrief()).ToArray() }).ToArray(); } }