Пример #1
0
        private void ButtonPayOnClick(object sender, EventArgs eventArgs)
        {
            var builder = new AlertDialog.Builder(this);

            builder.SetTitle("Вы точно хотите внести на счет?");
            builder.SetPositiveButton("ОК", (o, args) =>
            {
                float.TryParse(_inputPay.Text, out var amount);

                var model = new CustomPayRequest(amount, _credit.ServerId);

                if (!model.IsValid(ShowError))
                {
                    return;
                }

                ThreadPool.QueueUserWorkItem(w =>
                {
                    ShowLoaderInMainThread();

                    var commandDelegate = new CommandDelegate <CustomPayResponce>(OnSuccessCustomPay, ShowError, ShowErrorNotEnternet);
                    var command         = new CustomPayCommand(LocalDb.Instance, commandDelegate);
                    command.Execute(model);

                    DissmissLoaderInMainThread();
                });
            });
            builder.SetNegativeButton("Нет", (o, args) => { });
            builder.Create().Show();
        }
Пример #2
0
        public JsonResult CustomPay([FromBody] CustomPayRequest model)
        {
            var authorization = GetUserWithToken();

            if (authorization.Error != null)
            {
                return(Json(authorization.Error));
            }

            var credit = Context.Credits.FirstOrDefault(w => w.Id == model.IdCredit);

            if (credit == null)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(new JsonResult(new Error("bad", "Нет такого кредита")));
            }
            credit.Rest += model.Amount;
            Context.SaveChanges();

            return(Json(new CustomPayResponce()
            {
                Credit = credit,
            }));
        }