Ejemplo n.º 1
0
        public void UpdateRecipe(Recipe item)
        {
            // update record in db
            bool ok = DBHelper.Update(item);

            if (!ok)
            {
                throw new InvalidOperationException();
            }

            // remove item from old group if category is changed
            bool isRemoved = false;

            foreach (var group in GroupedRecipes)
            {
                if (group.Contains(item) && (string)group.Key != item.Category)
                {
                    group.Remove(item);
                    isRemoved = true;
                }
            }

            // add item to new group if needed
            if (isRemoved)
            {
                GroupedRecipes.GetOrAddGroup(item.Category).Add(item);

                // recount items in categories
                RecipeCategories.CountItemsFrom(GroupedRecipes);
            }
        }
Ejemplo n.º 2
0
        public void DeleteRecipe(Recipe item)
        {
            // delete record from db
            bool ok = DBHelper.Delete(item);

            if (!ok)
            {
                throw new InvalidOperationException();
            }

            // remove item from collection
            Recipes.Remove(item);

            // remove item from grouped collection
            GroupedRecipes.GetOrAddGroup(item.Category).Remove(item);

            // recount items in categories
            RecipeCategories.CountItemsFrom(GroupedRecipes);
        }
Ejemplo n.º 3
0
        public void AddRecipe(Recipe item)
        {
            // add new record to database
            bool ok = DBHelper.Insert(item);

            if (!ok)
            {
                throw new InvalidOperationException();
            }

            // add item to collection
            Recipes.Add(item);

            // add item to grouped collection
            GroupedRecipes.GetOrAddGroup(item.Category).Add(item);

            // recount items in categories
            RecipeCategories.CountItemsFrom(GroupedRecipes);
        }