async void DeleteClicked(object sender, EventArgs e) { var answer = await DisplayAlert("Confirm Delete", "Are you certain that you want to delete " + character.CharacterName + "?", "Yes", "No"); if (answer == true) { try { CharacterRepository ch = new CharacterRepository(); await ch.DeleteCharacter(character); thisApp.needCharacterRefresh = true; await Navigation.PopAsync(); } catch (AggregateException ex) { string errMsg = ""; foreach (var exception in ex.InnerExceptions) { errMsg += Environment.NewLine + exception.Message; } await DisplayAlert("One or more exceptions has occurred:", errMsg, "Ok"); } catch (ApiException apiEx) { var sb = new StringBuilder(); sb.AppendLine("Errors:"); foreach (var error in apiEx.Errors) { sb.AppendLine("-" + error); } await DisplayAlert("Problem Deleting the Character:", sb.ToString(), "Ok"); } catch (Exception ex) { if (ex.GetBaseException().Message.Contains("connection with the server")) { await DisplayAlert("Error", "No connection with the server.", "Ok"); } else { await DisplayAlert("Error", "Could not complete operation.", "Ok"); } } } }
public async Task DeleteCharacter(Character character) { characterRepository.DeleteCharacter(character.CharacterId); }