private async void DeleteItem(Item item) { var resp = await _dialogService.DisplayAlertAsync("", "Desea eliminar este item?", "Ok", "Cancelar"); if (!resp || item == null) { return; } ItemsByCategory.Remove(item); Items.Remove(item); await _cache.InsertLocalObject(CacheKeyDictionary.ItemList, Items); }
public async void DeleteCategory(Category cat) { if (cat == null) { return; } var resp = await _dialogService.DisplayAlertAsync("", "Desea eliminar esta categoria?", "Ok", "Cancelar"); if (!resp) { return; } var categories = (Views.MasterPage.Current.BindingContext as MasterPageViewModel)?.MenuItems; if (!categories.Contains(cat)) { return; } categories.Remove(cat); (Views.MasterPage.Current.BindingContext as MasterPageViewModel).MenuItems = categories; var items = Items.ToList(); foreach (var item in items) { if (item.Category == cat.DisplayName) { if (ItemsByCategory.Contains(item)) { ItemsByCategory.Remove(item); } Items.Remove(item); } } ShowItemsByCategory(null, true); await _cache.InsertLocalObject(CacheKeyDictionary.ItemList, Items); await _cache.InsertLocalObject(CacheKeyDictionary.CategoryItems, categories); }
public override async void OnNavigatedTo(NavigationParameters parameters) { if (parameters.ContainsKey("itemCreated")) { var itemSelected = (Item)parameters["itemCreated"]; itemSelected.Id = (Items?.Count > 0)? Items.Last().Id + 1 : 1; Items.Add(itemSelected); if (_currentCategory == null) { ItemsByCategory.Add(itemSelected); } else if (itemSelected.Category == _currentCategory?.DisplayName) { ItemsByCategory.Add(itemSelected); } if (itemSelected.Date.Date == DateTime.Today.Date) { ShowNotification(0, true); } await _cache.InsertLocalObject(CacheKeyDictionary.ItemList, Items); } if (parameters.ContainsKey("itemEdited")) { var newItem = (Item)parameters["itemEdited"]; //by cat var iEdited = ItemsByCategory.Single(i => i.Id == newItem.Id); var idxNewItem = ItemsByCategory.IndexOf(iEdited); ItemsByCategory.Remove(iEdited); ItemsByCategory = _itemsByCategory; if (_currentCategory == null) { ItemsByCategory.Insert(idxNewItem, newItem); } else if (newItem.Category == _currentCategory.DisplayName) { ItemsByCategory.Insert(idxNewItem, newItem); } //origin var itemEdited = Items.Single(i => i.Id == newItem.Id); var indexNewItem = Items.IndexOf(itemEdited); Items.Remove(itemEdited); Items.Insert(indexNewItem, newItem); await _cache.InsertLocalObject(CacheKeyDictionary.ItemList, Items); } if (parameters.ContainsKey("itemCompleted")) { var newItem = (Item)parameters["itemCompleted"]; var itemEdited = Items.Single(i => i.Id == newItem.Id); itemEdited.Completed = true; await _cache.InsertLocalObject(CacheKeyDictionary.ItemList, Items); } }