Beispiel #1
0
        public void UpdateCategory(Category category, CategoryList list, string oldname = null)
        {
            // update record in database
            string tableName = GetDBTableName(list);
            bool   ok        = DBHelper.Update(category, tableName);

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


            if (oldname != null && list == IngredientCategories)
            {
                // update category name of Ingredient objects
                var    group   = GroupedIngredients.GetOrAddGroup(oldname);
                string newName = category.Name;
                group.Key = newName;
                foreach (var item in group)
                {
                    var ingredient = item as Ingredient;
                    ingredient.Category = newName;
                    UpdateIngredient(ingredient);
                }

                // recreate grouped records
                // (otherwise there is display problem in grid view)
                this.GroupedIngredients = Ingredients.GetGroupedList();

                // update item count of all categories
                IngredientCategories.CountItemsFrom(GroupedIngredients);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes an ingredient object.
 /// </summary>
 /// <param name="name">The name of the ingredient.</param>
 /// <param name="category">The category of the ingredient.</param>
 /// <param name="quantity">The quantity of the ingredient (in specified unit).</param>
 /// <param name="unit">The unit in which the ingredient is measured.</param>
 public Ingredient(string name, IngredientCategories category, float quantity, Units unit)
 {
     Name     = name;
     Category = category;
     Quantity = quantity;
     Unit     = unit;
 }
Beispiel #3
0
        public void UpdateIngredient(Ingredient 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 GroupedIngredients)
            {
                if (group.Contains(item) && (string)group.Key != item.Category)
                {
                    group.Remove(item);
                    isRemoved = true;
                }
            }

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

                // recount items in categories
                IngredientCategories.CountItemsFrom(GroupedIngredients);
            }
        }
Beispiel #4
0
 public void RemoveIngredientCategory(IngredientCategory ic)
 {
     foreach (var i in Ingredients)
     {
         i.Categories.RemoveAll(s => s.Name == ic.Name);
     }
     IngredientCategories.RemoveAll(s => s.Name == ic.Name);
 }
Beispiel #5
0
        // constructor
        private MainModelView()
        {
            InitializeDatabase();
            ReadAllFromDB();
            IngredientCategories.CountItemsFrom(GroupedIngredients);

            // async post-process for loading thumbnails and delete unused thumbnails
            LoadThumbtails().ContinueWith(t => DeleteUnusedThumbnails());
        }
Beispiel #6
0
        public void DeleteIngredient(Ingredient item)
        {
            // delete record from db
            bool ok = DBHelper.Delete(item);

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

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

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

            // recount items in categories
            IngredientCategories.CountItemsFrom(GroupedIngredients);
        }
Beispiel #7
0
        public void AddIngredient(Ingredient item)
        {
            // add new record to database
            bool ok = DBHelper.Insert(item);

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

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

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

            // recount items in categories
            IngredientCategories.CountItemsFrom(GroupedIngredients);
        }
Beispiel #8
0
        // public methods
        public void AddCategory(Category category, CategoryList list)
        {
            // add new record to database
            string tableName = GetDBTableName(list);
            bool   ok        = DBHelper.Insert(category, tableName);

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

            // add to catagory list
            list.Add(category);

            // update item count of new category
            if (list == IngredientCategories)
            {
                IngredientCategories.CountItemsFrom(GroupedIngredients);
            }
        }
Beispiel #9
0
 /// <summary>
 /// Initializes an ingredient object of the Common Unit type.
 /// </summary>
 /// <param name="name">The name of the ingredient.</param>
 /// <param name="category">The category of the ingredient.</param>
 public Ingredient(string name, IngredientCategories category) : this(name, category, -1f, Units.Common)
 {
 }