コード例 #1
0
ファイル: MockContext.cs プロジェクト: relimited/core
 public ShoppingListResult UpdateShoppingList(ShoppingList list, ShoppingListUpdateCommand[] updates, string newName = null)
 {
     throw new NotImplementedException();
 }
コード例 #2
0
        /// <summary>
        /// Updates a shopping list.
        /// </summary>
        /// <param name="list">A shopping list owned by the current user.</param>
        /// <param name="updates">A set of update commands indicating how the shopping list should be updated.</param>
        /// <param name="newName">An optional new name for this shopping list.</param>
        /// <returns></returns>
        public virtual ShoppingListResult UpdateShoppingList(ShoppingList list, ShoppingListUpdateCommand[] updates, string newName = null)
        {
            // Aggregate new items
            var parsedIngredients = Parser.ParseAll(updates.Where(u => !string.IsNullOrWhiteSpace(u.NewRaw)).Select(r => r.NewRaw).ToArray()).ToList();

            var recipeAggregation = this.AggregateRecipes(updates.Where(u => u.NewRecipe != null)
                .Select(r => r.NewRecipe.Id).ToArray());

            var ingredientsAggregation = updates.Where(u => u.NewIngredient != null)
                .Select(i => new IngredientAggregation(i.NewIngredient, null));

            var ingredientUsages = this.AggregateIngredients(updates.Where(u => u.NewUsage != null)
                .Select(u => u.NewUsage).ToArray());

            var parsedUsages = this.AggregateIngredients(parsedIngredients.Where(u => u is Match)
                .Select(u => u.Usage).ToArray());

            var rawInputs = parsedIngredients
                .Where(u => u is NoMatch)
                .Select(u => new ShoppingListItem(u.Input));

            var newItems = recipeAggregation
                .Concat(ingredientsAggregation)
                .Concat(ingredientUsages)
                .Concat(parsedUsages)
                .Concat(rawInputs)
                .ToArray();

            var removedItems = updates
                .Where(u => u.Command == ShoppingListUpdateType.RemoveItem)
                .Select(i => i.RemoveItem.Value)
                .ToArray();
            var modifiedItems = updates
                .Where(u => u.Command == ShoppingListUpdateType.ModifyItem)
                .Select(i => i.ModifyItem)
                .ToArray();

            return this.Adapter.UpdateShoppingList(this.Identity, list.Id, removedItems, modifiedItems, newItems, newName);
        }