public async void SaveShopping(SaveShoppingRequest saveShoppingRequest, Action success, Action <BaseResponseModel> failed) { bool IsNetwork = true;//await DependencyService.Get<IMediaService>().CheckNewworkConnectivity(); if (IsNetwork) { var url = string.Format("{0}saveshoppinglist.php", _settingsManager.ApiHost); await Task.Factory.StartNew(() => { var result = _apiProvider.Post <BaseResponseModel, SaveShoppingRequest>(url, saveShoppingRequest).Result; if (result.IsSuccessful) { if (success != null) { saveShoppingResponse = result.Result; success.Invoke(); } } else { failed.Invoke(result.Result); } }); } else { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.Alert(error, null, "OK"); } }
public void SaveShoppingExecute() { try { var obj = new SaveShoppingRequest() { Recipe_Id = RecipeId, Ingredient_Id = 5, Member_Id = Convert.ToInt32(App.AppSetup.HomeViewModel.UserId) }; UserDialogs.Instance.ShowLoading("Requesting.."); userManager.SaveShopping(obj, () => { UserDialogs.Instance.HideLoading(); var saveShoppingResponse = userManager.SaveShoppingResponse; if (saveShoppingResponse.StatusCode == 200) { UserDialogs.Instance.Alert(saveShoppingResponse.Message, null, "OK"); } else { UserDialogs.Instance.Alert(saveShoppingResponse.Message, null, "OK"); } }, (requestFailedReason) => { Device.BeginInvokeOnMainThread(() => { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.Alert(requestFailedReason.Message, null, "OK"); }); }); } catch (Exception ex) { UserDialogs.Instance.HideLoading(); UserDialogs.Instance.Alert(ex.Message, null, "OK"); } }