Beispiel #1
0
        public IHttpActionResult Put(long id, [FromBody] EditWalletInfo model)
        {
            var wallet = DB.Wallet.FirstOrDefault(x => x.User.Id == UserId && x.Id == id);

            if (wallet == null)
            {
                return(NotFound());
            }

            Helpers.ObjectMapper.CopyPropertiesTo(model, wallet, Helpers.ObjectMapper.UpdateFlag.DeferUpdateOnNull | Helpers.ObjectMapper.UpdateFlag.DenoteEmptyStringsAsNull);
            DB.SaveChanges();
            return(Ok(Map <WalletInfo>(wallet)));
        }
        public override void OnResume()
        {
            (Dialog as AlertDialog)?.GetButton((int)DialogButtonType.Positive).SetOnClickListener(new ClickListener(async delegate
            {
                string provider = networkProvider[networkProviderSpinner.SelectedItemPosition];
                string value    = tbPhoneNo.EditText.TrimInput();

                //  Validate phone no
                if (tbPhoneNo.SetError(InputHandler.IsValidPhone(value) ? null : "Invalid phone number"))
                {
                    return;
                }

                //
                var proxy = ProxyFactory.GetProxyInstace();

                if (isEdit)
                {
                    var editInfo = new EditWalletInfo();

                    if (editInfo.Value != value)
                    {
                        editInfo.Value = value;
                    }

                    if (editInfo.Provider != provider)
                    {
                        editInfo.Provider = provider;
                    }

                    if (editInfo.AnyUpdate())
                    {
                        using (Activity.ShowProgress(null, "Saving changes, please hold on..."))
                        {
                            var response = await proxy.ExecuteAsync(API.Endpoints.WalletEndpoints.UpdateWallet(walletInfo.Id, editInfo));
                            if (response.Successful)
                            {
                                //
                                walletInfo.Provider = provider;
                                walletInfo.Value    = value;

                                //
                                OnUpdated?.Invoke(this, walletInfo);

                                //
                                Dialog.Dismiss();
                            }
                            else
                            {
                                Toast.MakeText(Activity, response.GetErrorDescription(), ToastLength.Short).Show();
                            }
                        }
                    }
                }
                else
                {
                    using (Activity.ShowProgress(null, "Creating wallet, please hold on..."))
                    {
                        var response = await proxy.ExecuteAsync(API.Endpoints.WalletEndpoints.CreateWallet(provider, value));
                        if (response.Successful)
                        {
                            OnCreated?.Invoke(this, await response.GetDataAsync <WalletInfo>());

                            //
                            Dialog.Dismiss();
                        }
                        else
                        {
                            Toast.MakeText(Activity, response.GetErrorDescription(), ToastLength.Short).Show();
                        }
                    }
                }
            }));

            base.OnResume();
        }
Beispiel #3
0
 public static IEndpoint UpdateWallet(long id, EditWalletInfo walletInfo) => new ApiEndpoint($"{BaseUri}/{id}", HttpMethod.Put, walletInfo);