Beispiel #1
0
        public bool Update(ShoppingListItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item can not be null");
            }
            int index = shoppingList.FindIndex(p => p.Name == item.Name);

            if (index == -1)
            {
                return(false);
            }
            shoppingList.RemoveAt(index);
            shoppingList.Add(item);
            return(true);
        }
Beispiel #2
0
        public ShoppingListItem Add(ShoppingListItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("shopping list item");
            }

            int index = shoppingList.FindIndex(i => i.Name == item.Name);

            if (index != -1)
            {
                throw new Exception("an item with the same name is already in the list");
            }

            shoppingList.Add(item);
            return(item);
        }