private async Task SaveCategoryAsync() { if (!await CanSaveCategoryAsync()) { return; } await DialogService.DisplayPopupAsync(); var parameters = new NavigationParameters(); if (IsUpdated) { parameters.Add("IsUpdated", true); } if (IsNewCategory) { var categoryID = await FirebaseService.InsertCategoryAsync(Category); for (int i = States.Count - 1; i >= 0; i--) { States[i].CategoryID = categoryID; await FirebaseService.InsertStateAsync(States[i]); } } else { await FirebaseService.UpdateCategoryAsync(Category); foreach (var state in States) { if (state.StateID == null) { await FirebaseService.InsertStateAsync(state); } else { await FirebaseService.UpdateStateAsync(state); } } foreach (var state in DeletedStates) { await FirebaseService.DeleteStateAsync(state); } } await DialogService.PopAsync(); await NavigationService.GoBackAsync(parameters); }