private async void CategoryAdd_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(newCategory.Name) && newCategory.Id != default(Guid)) { Category returnFocus = UsrNotes.NoteCategories.Where(x => x.Id == newCategory.Id).FirstOrDefault(); CagegoryList.SelectedIndex = returnFocus == null ? -1 : UsrNotes.NoteCategories.LastIndexOf(returnFocus); return; } Category currentCat; if (newCategory.Id == default(Guid) || UsrNotes.NoteCategories.Where(x => x.Id == newCategory.Id).FirstOrDefault()?.Name == newCategory.Name) //Не изменяя текста нажали Save { currentCat = await provider.CreateCategory(owner, "New Category"); } else { currentCat = await provider.UpdateCategory(newCategory); } UsrNotes.UpdateCurrentCategoryList(await provider.GetUserCategories(owner)); Category focusedCategory = UsrNotes.NoteCategories.Where(x => x.Id == currentCat.Id).FirstOrDefault(); CagegoryList.SelectedIndex = focusedCategory == null ? -1 : UsrNotes.NoteCategories.LastIndexOf(focusedCategory); newCategory = new Category(); }
private async void CategoryDelete_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(newCategory.Name) && newCategory.Id == default(Guid) && CagegoryList.SelectedIndex == -1) { Category returnFocus = UsrNotes.NoteCategories.Where(x => x.Id == newCategory.Id).FirstOrDefault(); CagegoryList.SelectedIndex = returnFocus == null ? -1 : UsrNotes.NoteCategories.LastIndexOf(returnFocus); return; } Guid selectedCategory = UsrNotes.NoteCategories[CagegoryList.SelectedIndex].Id; await provider.DeleteCategory(selectedCategory); UsrNotes.UpdateCurrentCategoryList(await provider.GetUserCategories(owner)); CagegoryList.SelectedIndex = 0; newCategory = new Category(); }