Exemplo n.º 1
0
        public IActionResult WithdrawMoney(WithdrawMoneyRequest request)
        {
            Account account = new Account(_eventStore.GetEvents());
            var     result  = account.WithdrawMoney(request.Amount);

            if (result.IsFailure)
            {
                return(BadRequest(result.Error.ErrorMessage));
            }

            _eventStore.AddEvents(account.Changes);
            return(Ok(result.Value));
        }
Exemplo n.º 2
0
        public ApiResult <string> WithdrawMoneyCheckUserPermissionAndClientScope([FromBody] WithdrawMoneyRequest value)
        {
            if (!ModelState.IsValid)
            {
                return(new ApiResult <string>()
                {
                    code = (int)BasicControllerEnums.UnprocessableEntity,

                    message = ModelErrors(),
                });
            }

            if (value.Money > 2000)
            {
                return(new ApiResult <string>(l, DemoControllerEnums.WithdrawMoneyMoreThan2000));
            }

            return(new ApiResult <string>("2000"));
        }
Exemplo n.º 3
0
        public static async Task <WithdrawMoneyResponse> WithdrawMoney(WithdrawMoneyRequest withdrawMoneyRequest)
        {
            await Session.GetTokenIfEmptyAsync(AuthTokenType.Simple);

            var token = await Session.GetAuthTokenAsync(AuthTokenType.Simple);

            if (string.IsNullOrEmpty(token))
            {
                throw new UnauthorizedAccessException("User is not logged in to perform the action: Withdraw Money");
            }

            if (withdrawMoneyRequest == null)
            {
                return(null);
            }

            RestWrapper restWrapper = new RestWrapper();

            var response =
                await
                restWrapper.Post <WithdrawMoneyResponse>(Service.WithdrawMoney,
                                                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("amount", withdrawMoneyRequest.Amount.ToString()),
                new KeyValuePair <string, string>("currency", "INR"),
                new KeyValuePair <string, string>("owner", withdrawMoneyRequest.AccoutnHolderName),
                new KeyValuePair <string, string>("account", withdrawMoneyRequest.AccountNo),
                new KeyValuePair <string, string>("ifsc", withdrawMoneyRequest.IFSC)
            }, AuthTokenType.Simple);

            if (!(response is Error))
            {
                return(response as WithdrawMoneyResponse);
            }

            Utility.ParseAndThrowError(((Error)response).Response);
            return(null);
        }