private async void DeleteActivity() { ProgressDialog progress = new ProgressDialog(this); progress.SetMessage(Resources.GetString(Resource.String.PleaseWait)); progress.Show(); ServerResponse <string> resp = await ServerUtils.Delete <string>("/api/learningactivities?id=" + learningActivity.Id); progress.Dismiss(); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show(); return; } if (resp.Success) { Toast.MakeText(this, Resource.String.uploadsUploadSuccessTitle, ToastLength.Long).Show(); } else { Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show(); } MainLandingFragment.ForceRefresh = true; dbManager.DeleteProgress(learningActivity.Id); Finish(); }
private async Task DeleteRemoteActivity() { ShowLoadingOverlay(); ServerResponse <string> resp = await ServerUtils.Delete <string>("/api/learningactivities?id=" + thisActivity.Id); HideLoadingOverlay(); if (resp == null) { var suppress = AppUtils.SignOut(this); return; } if (resp.Success) { DatabaseManager dbManager = await Storage.GetDatabaseManager(false); dbManager.DeleteCachedActivity(thisActivity); Toast.ShowToast("Activity Deleted"); NavigationController.DismissViewController(true, null); } else { Toast.ShowToast("Error connecting to the server"); } }
public override bool OnOptionsItemSelected(IMenuItem item) { if (item.ItemId == global::Android.Resource.Id.Home) { OnBackPressed(); return(true); } if (item.ItemId != Resource.Id.menudelete) { return(base.OnOptionsItemSelected(item)); } using (var builder = new global::Android.Support.V7.App.AlertDialog.Builder(this)) { builder.SetTitle(Resource.String.deleteTitle) .SetMessage(Resource.String.deleteMessage) .SetNegativeButton(Resource.String.dialog_cancel, (a, e) => { }) .SetPositiveButton(Resource.String.DeleteBtn, async(a, e) => { if (editingSubmitted) { using (ProgressDialog prog = new ProgressDialog(this)) { prog.SetMessage(Resources.GetString(Resource.String.PleaseWait)); prog.Show(); ServerResponse <string> resp = await ServerUtils.Delete <string>("/api/learningactivities?id=" + newActivity.Id).ConfigureAwait(false); RunOnUiThread(() => prog.Dismiss()); if (resp == null) { var suppress = AndroidUtils.ReturnToSignIn(this); RunOnUiThread(() => Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show()); } else if (resp.Success) { RunOnUiThread(() => Toast.MakeText(this, Resource.String.uploadsUploadSuccessTitle, ToastLength.Long).Show()); MainMyCreationsFragment.ForceRefresh = true; Finish(); } else { RunOnUiThread(() => Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show()); } } } else { DatabaseManager db = await AndroidUtils.GetDbManager().ConfigureAwait(false); var localActivities = JsonConvert.DeserializeObject <List <LearningActivity> >(db.CurrentUser.LocalCreatedActivitiesJson); localActivities.Remove(localActivities.FirstOrDefault(act => act.Id == newActivity.Id)); db.CurrentUser.LocalCreatedActivitiesJson = JsonConvert.SerializeObject(localActivities); db.AddUser(db.CurrentUser); MainMyCreationsFragment.ForceRefresh = true; Finish(); } }) .Show(); } return(true); }