public IList<ShoppingList> List()
        {
            var options = new GetShoppingListOptions
            {
                LoadItems = this.loadItems
            };

            return this.context.GetShoppingLists(this.listsToLoad, options);
        }
コード例 #2
0
ファイル: MockContext.cs プロジェクト: relimited/core
 public ShoppingList[] GetShoppingLists(IList<ShoppingList> lists, GetShoppingListOptions options)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
 /// <summary>
 /// Returns one or more saved shopping lists from the current user.
 /// </summary>
 /// <param name="lists">A list of ShoppingList objects indicating the ID of the list to load, or ShoppingList.Default for the default list.</param>
 /// <param name="options">Indicates what data to load.  Use GetShoppingListOptions.None to simply load the names of the lists.</param>
 /// <returns>An array of ShoppingList objects with all the desired properties loaded.</returns>
 public virtual ShoppingList[] GetShoppingLists(IList<ShoppingList> lists, GetShoppingListOptions options)
 {
     return this.Adapter.GetShoppingLists(this.Identity, lists, options);
 }
コード例 #4
0
ファイル: DatabaseAdapter.cs プロジェクト: relimited/core
        public ShoppingList[] GetShoppingLists(AuthIdentity identity, IList<ShoppingList> lists, GetShoppingListOptions options)
        {
            using (var session = GetSession())
             {
            var loadDef = true;
            var query = session.QueryOver<Models.ShoppingLists>()
               .Where(p => p.UserId == identity.UserId);

            if (lists != null) // Load individual lists
            {
               loadDef = lists.Contains(ShoppingList.Default);
               var ids = lists.Where(l => l.Id.HasValue).Select(l => l.Id.Value).ToArray();
               query = query.AndRestrictionOn(x => x.ShoppingListId).IsInG(ids);
            }

            var dbLists = query.List();
            var ret = new List<ShoppingList>();

            if (loadDef)
               ret.Add(ShoppingList.Default);

            ret.AddRange(dbLists.Select(l => l.AsShoppingList()));

            if (!options.LoadItems) // We're done!
               return ret.ToArray();

            // Load items into each list
            ICriterion filter = (loadDef
               ? Expression.Or(Expression.IsNull("ShoppingList"), Expression.InG("ShoppingList", dbLists)) // Menu can be null, or in loaded menu list
               : Expression.InG("ShoppingList", dbLists)); // Menu must be in loaded menu list

            var dbItems = session.QueryOver<ShoppingListItems>()
               .Fetch(prop => prop.Ingredient).Eager
               .Fetch(prop => prop.Recipe).Eager
               .Where(p => p.UserId == identity.UserId)
               .Where(filter)
               .List();

            return ret.Select(m =>
               new ShoppingList(
                  m.Id,
                  m.Title,
                  (m.Id.HasValue
                     ? dbItems.Where(f => f.ShoppingList != null && f.ShoppingList.ShoppingListId == m.Id)
                     : dbItems.Where(f => f.ShoppingList == null)).Select(r => r.AsShoppingListItem())
                  )).ToArray();
             }
        }
コード例 #5
0
        /// <summary>
        /// Returns one or more saved shopping lists from the current user.
        /// </summary>
        /// <param name="lists">A list of ShoppingList objects indicating the ID of the list to load, or ShoppingList.Default for the default list.</param>
        /// <param name="options">Indicates what data to load.  Use GetShoppingListOptions.None to simply load the names of the lists.</param>
        /// <returns>An array of ShoppingList objects with all the desired properties loaded.</returns>
        public ShoppingList[] GetShoppingLists(IList<ShoppingList> lists, GetShoppingListOptions options)
        {
            var loadDef = true;
             var query = store.ShoppingLists
            .Where(p => p.UserId == Identity.UserId);

             if (lists != null) // Load individual lists
             {
            loadDef = lists.Contains(ShoppingList.DefaultList);
            var ids = lists.Where(l => l.Id.HasValue).Select(l => l.Id.Value).ToArray();
            query = query.Where(p => ids.Contains(p.ShoppingListId));
             }

             var dbLists = query.ToList();

             if (!options.HasLoadedItems) // We're done!
             {
            return (loadDef ? new[] {ShoppingList.DefaultList} : new ShoppingList[0])
               .Concat(dbLists.Select(Data.DTO.ShoppingLists.ToShoppingList))
               .ToArray();
             }

             // All user's shopping list items
             var dbItems = store.ShoppingListItems
            .Where(p => p.UserId == Identity.UserId)
            .ToList();

             var indexRecipes = store.GetIndexedRecipes();
             var indexIngredients = store.GetIndexedIngredients();

             var ret = new List<ShoppingList>();
             if (loadDef) ret.Add(ShoppingList.DefaultList);
             ret.AddRange(dbLists.Select(Data.DTO.ShoppingLists.ToShoppingList));

             // Add items to list
             foreach (var list in ret)
             {
            var itemsInList = dbItems.Where(p => p.ShoppingListId.Equals(list.Id));
            var items = itemsInList.Select(item =>
               new ShoppingListItem(item.ItemId)
               {
                  Raw = item.Raw,
                  Ingredient = item.IngredientId.HasValue ? Data.DTO.Ingredients.ToIngredient(indexIngredients[item.IngredientId.Value]) : null,
                  Recipe = item.RecipeId.HasValue ? Data.DTO.Recipes.ToRecipeBrief(indexRecipes[item.RecipeId.Value]) : null,
                  CrossedOut = item.CrossedOut,
                  Amount = (item.Qty.HasValue && item.Unit.HasValue) ? new Amount(item.Qty.Value, item.Unit.Value) : null
               });

            list.AddItems(items.ToList());
             }

             return ret.ToArray();
        }
        public ShoppingList[] GetShoppingLists(
            AuthorIdentity identity, 
            IList<ShoppingList> lists, 
            GetShoppingListOptions options)
        {
            using (var session = this.GetSession())
            {
                var defaultsLoaded = true;
                var query = session.QueryOver<ShoppingLists>().Where(p => p.UserId == identity.UserId);

                defaultsLoaded = LoadIndividualLists(lists, defaultsLoaded, ref query);

                var databaseLists = query.List();
                var shopingList = new List<ShoppingList>();

                if (defaultsLoaded)
                {
                    shopingList.Add(ShoppingList.Default);
                }

                shopingList.AddRange(databaseLists.Select(l => l.AsShoppingList()));

                if (!options.LoadItems)
                {
                    return shopingList.ToArray();
                }

                var databaseItems = LoadItemsIntoLists(identity, defaultsLoaded, databaseLists, session);

                return
                    shopingList.Select(
                        m =>
                        new ShoppingList(
                            m.Id,
                            m.Title,
                            (m.Id.HasValue
                                 ? databaseItems.Where(f => f.ShoppingList != null && f.ShoppingList.ShoppingListId == m.Id)
                                 : databaseItems.Where(f => f.ShoppingList == null)).Select(r => r.AsShoppingListItem())))
                        .ToArray();
            }
        }
コード例 #7
0
        public IList<ShoppingList> List()
        {
            var options = new GetShoppingListOptions
             {
            HasLoadedItems = loadItems
             };

             return context.GetShoppingLists(listsToLoad, options);
        }
コード例 #8
0
 public IList<ShoppingList> List()
 {
     var options = new GetShoppingListOptions(this.loadItems);
     var result = this.context.GetShoppingLists(this.listsToLoad, options);
     return result;
 }