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); } }
/// <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; }
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); } }
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); }
// constructor private MainModelView() { InitializeDatabase(); ReadAllFromDB(); IngredientCategories.CountItemsFrom(GroupedIngredients); // async post-process for loading thumbnails and delete unused thumbnails LoadThumbtails().ContinueWith(t => DeleteUnusedThumbnails()); }
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); }
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); }
// 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); } }
/// <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) { }