public void ShowItemsByCategory(Category categoryItem, bool showAll = false) { ItemsByCategory = new ObservableCollection <Item>(); _currentCategory = categoryItem; if (string.IsNullOrEmpty(categoryItem?.DisplayName) || showAll) { Title = "Todas las tareas"; ItemsByCategory = new ObservableCollection <Item>(Items); return; } foreach (var item in Items) { if (item.Category == categoryItem.DisplayName) { ItemsByCategory.Add(item); } } Title = categoryItem.DisplayName; }
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); } }