public async void CreateOrUpdate( Argument argument, Action<Argument> success = null, Action<string> failure = null ) { bool update = argument.Id > 0; var parameters = new Dictionary<string, object> { {paramProductGroupId,argument.ProductGroupId}, {paramFeature,argument.Feature}, {paramBenefit,argument.Benefit} }; var method = HTTPMethod.POST; var path = string.Format(pathArgumentCreate); if (update) { parameters.Add(paramArgumentId, argument.Id); method = HTTPMethod.PUT; path = string.Format(pathArgumentUpdate, argument.Id); } var request = new HttpRequest <ResponseJsonArgument> { Method = method, Path = path, Parameters = ParametersWithDeviceInfo(parameters), Success = response => { SynchronizationManager.Instance.CancelWriteToDatabaseIfSynchronizationInProgress(); DatabaseHelper.Replace<Argument>(response.MappedResponse.Argument); DatabaseHelper.Replace<User>(response.MappedResponse.User); if ( success != null ) { success(response.MappedResponse.Argument); } }, Failure = response => { if ( failure != null ) { failure(response.Error.LocalizedMessage); } } }; await request.Perform(); }
void SaveArgument(object o, EventArgs e) { View.EndEditing(true); if (formController.Validator.Validate()) { if (!IsNetworkAvailable()) { ShowAlert(ServiceAccessError.ErrorHostUnreachable.LocalizedMessage); return; } Argument = formController.Argument; Argument.ProductGroupId = ProductGroupsDataSource.SelectedProductGroup.Id; ShowHud(I18n.Sending); ServiceProviderArgument.Instance.CreateOrUpdate( Argument, result => { HideHud(); InvokeOnMainThread(() => NavigationController.PopViewControllerAnimated(true)); }, errorMessage => { HideHud(); ShowAlert(errorMessage); } ); } else { ShowAlert(string.Join("\n", formController.Validator.Errors)); } }
void PerformRateRequest() { if (!IsNetworkAvailable()) { ShowAlert(ServiceAccessError.ErrorHostUnreachable.LocalizedMessage); RestartRatingButtons(); return; } ShowHud(I18n.Sending); ServiceProviderArgument.Instance.Rate( Argument, selectedRating, updatedArgument => { Argument = updatedArgument; UpdateView(); HideHud(); }, errorMessage => { RestartRatingButtons(); HideHud(); ShowAlert(errorMessage); } ); }
public async void Rate( Argument argument, float rating, Action<Argument> success = null, Action<string> failure = null ) { var parameters = new Dictionary<string, object> { {paramRateValue,rating} }; var request = new HttpRequest <ResponseJsonArgumentRating> { Method = HTTPMethod.POST, Path = string.Format(pathRate,argument.Id), Parameters = ParametersWithDeviceInfo(parameters), Success = response => { SynchronizationManager.Instance.CancelWriteToDatabaseIfSynchronizationInProgress(); DatabaseHelper.Replace<Argument>(response.MappedResponse.Argument); DatabaseHelper.Replace<User>(response.MappedResponse.User); if ( success != null ) { success(response.MappedResponse.Argument); } }, Failure = response => { if ( failure != null ) { failure(response.Error.LocalizedMessage); } } }; await request.Perform(); }