public void SaveShoppingItem(ShoppingItem shoppingItem) { if (shoppingItem.ID == 0) { _connection.Insert(shoppingItem); } else { _connection.Update(shoppingItem); } // add to inventory? if (shoppingItem.IsCompleted) { if (shoppingItem.MakeItem && shoppingItem.ItemID == 0) { var item = new Item(); item.Name = shoppingItem.Name; item.Notes = shoppingItem.Notes; item.Quantity = shoppingItem.Quantity; item.QuantityForShoppingList = 0; item.DatePurchased = DateTime.Now; shoppingItem.ItemID = SaveItem(item); shoppingItem.MakeItem = false; SaveShoppingItem(shoppingItem); } } var message = new CollectionChangedMessage(this, true); _messenger.Publish(message); }
public void DeleteShoppingItem(int id) { _connection.Delete <ShoppingItem>(id); var message = new CollectionChangedMessage(this, true); _messenger.Publish(message); }
public void SaveFilters() { System.Diagnostics.Debug.WriteLine("FiltersViewModel.SaveFilters()"); Filters.Write(_filters.ToJson().ToString()); // reset stack if attribute changed if (_filters.Attribute != _initialAttribute) { _dataService.ResetAttributeStack(); } var message = new CollectionChangedMessage(this, true); _messenger.Publish(message); Close(this); }
public void DeleteItem(int id) { _connection.Delete <Item>(id); // remove shopping item if necessary try { DeleteShoppingItem(GetShoppingItemFromItem(id).ID); } catch (Exception) { System.Diagnostics.Debug.WriteLine("No corresponding shopping list item"); } var message = new CollectionChangedMessage(this, true); _messenger.Publish(message); }
public int SaveItem(Item item) { System.Diagnostics.Debug.WriteLine("Saving item with name: " + item.Name); item.Category = TrimPath(item.Category); item.Location = TrimPath(item.Location); if (item.ID == 0) { _connection.Insert(item); } else { _connection.Update(item); } // Add to shopping list if necessary if (item.QuantityForShoppingList > -1) { ShoppingItem shoppingItem = GetShoppingItemFromItem(item.ID); if (item.Quantity <= item.QuantityForShoppingList) { if (shoppingItem == null) { shoppingItem = new ShoppingItem(item.ID, item.Name, 1, item.Notes, false, false, new DateTime(1, 1, 1)); } // Set our desired shopping quantity to threshold + 1 shoppingItem.Quantity = item.QuantityForShoppingList - item.Quantity + 1; SaveShoppingItem(shoppingItem); } } var message = new CollectionChangedMessage(this, true); _messenger.Publish(message); return(item.ID); }
private void OnCollectionChanged(CollectionChangedMessage message) { ReloadList(); }
/// <summary> /// Called when an item has been added or modified. /// </summary> private void Refresh(CollectionChangedMessage message) { System.Diagnostics.Debug.WriteLine("InventoryViewModel.Refresh()"); Items = _dataService.AllItems(); }
private void OnCollectionChanged(CollectionChangedMessage obj) { UpdateLatest(); }
/// <summary> /// Called when the current working path has been updated. /// </summary> private void Refresh(CollectionChangedMessage message) { DataPaths = _dataService.GetChildPaths(); PresentablePaths = _dataService.GetPresentablePaths(DataPaths); }
private void UpdateSpinner(string path) { System.Diagnostics.Debug.WriteLine("You selected: " + path); SelectedIndex = -1; int index; try { index = PresentablePaths.IndexOf(path); } catch (Exception) { index = 0; } System.Diagnostics.Debug.WriteLine("This is index: " + index); System.Diagnostics.Debug.WriteLine("Stack count: " + _dataService.GetAttributeStack().Count); System.Diagnostics.Debug.WriteLine(string.Format("Attribute Path: '{0}'", _dataService.GetAttributePath())); // Do nothing if we are already at top (house) level if (index == 0 && !string.IsNullOrEmpty(_dataService.GetAttributePath())) { System.Diagnostics.Debug.WriteLine("going up!"); _dataService.PopAttribute(); } // Do nothing if user picked same room else if (index >= 1 && string.IsNullOrEmpty(_dataService.GetAttributePath())) { System.Diagnostics.Debug.WriteLine("selected root room"); System.Diagnostics.Debug.WriteLine("pushing: " + DataPaths[index]); _dataService.PushAttribute(DataPaths[index]); } else if (index > 1 && !string.IsNullOrEmpty(_dataService.GetAttributePath())) { System.Diagnostics.Debug.WriteLine("selected sub-room"); System.Diagnostics.Debug.WriteLine("pushing: " + DataPaths[index]); _dataService.PushAttribute(DataPaths[index]); } // reset path and give it the stack's values from root to child _dataService.SetAttributePath(""); string[] stackAsArray = _dataService.GetAttributeStack().ToArray(); string tmpAttrPath = _dataService.GetAttributePath(); for (int i = stackAsArray.Length - 1; i >= 0; i--) { tmpAttrPath += stackAsArray[i]; } _dataService.SetAttributePath(tmpAttrPath); System.Diagnostics.Debug.WriteLine(string.Format("path to query: '{0}'", _dataService.GetAttributePath())); // Set index for view to update selection if (!string.IsNullOrEmpty(_dataService.GetAttributePath())) { SelectedIndex = 1; } else { SelectedIndex = 0; } var message = new CollectionChangedMessage(this, true); _messenger.Publish(message); }