Ejemplo n.º 1
0
        public ActionResult <double> Credit([Required, FromRoute] string accountNumber,
                                            [BindRequired, FromQuery] double sum,
                                            [Required, FromQuery] string memo)
        {
            double balance;

            try
            {
                memo = Util.Dequotify(memo);

                UserInputValidation.ValidateAccountNumber(accountNumber);
                UserInputValidation.ValidateAmount(sum);
                UserInputValidation.ValidateMemo(memo);

                var userInfo = User.GetUserInfo();
                var username = userInfo.AccountsUsername;

                sum = Util.TruncateMoneyValue(sum);

                using (var session = Logic.Login(Repository, username))
                {
                    Logic.ExecuteTransaction(session, accountNumber, AccountsLib.ETransactionType.Credit, sum, memo);

                    balance = Logic.GetBalance(session, accountNumber);
                }
            }
            catch (AccountsLibException ex)
            {
                return(new ActionFailureResult(new ApiResponse(500, ex.Message)));
            }

            return(balance);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Call the Accounts API to credit an account with some amount.
        /// </summary>
        /// <param name="accountNumber">The account to be modified.</param>
        /// <param name="amount">The (unsigned) amount to be credited to the account.</param>
        /// <param name="memo">A short note to be attached to this transaction.</param>
        /// <returns>The new balance for the modified account.</returns>
        ///
        public async Task <double> CreditAccount(string accountNumber, double amount, string memo)
        {
            UserInputValidation.ValidateAccountNumber(accountNumber);
            UserInputValidation.ValidateAmount(amount);
            UserInputValidation.ValidateMemo(memo);

            var queryString = $"api/accounts/credit/{accountNumber}?sum={Math.Abs(amount)}";

            if (memo != null)
            {
                queryString += $"&memo=\"{memo}\"";
            }

            var response = await this.InvokeApiAsync(Post, queryString);

            var content = await response.TryGetResponseContent();

            var balance = Double.Parse(content);

            return(balance);
        }