예제 #1
0
        public async Task <IActionResult> ApproveFunding(ApproveFundingDto approveFundingDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ResponseMessage.Message("Invalid Model", ModelState)));
            }

            var funding = _fundRepository.GetFundingById(approveFundingDto.FundingId);

            if (funding == null)
            {
                return(BadRequest(ResponseMessage.Message("Invalid funding Id", "funding with the id was not found", approveFundingDto)));
            }

            var wallet = _walletRepository.GetWalletById(funding.DestinationId);

            if (wallet == null)
            {
                return(BadRequest(ResponseMessage.Message("Invalid wallet Id", "wallet with the id was not found", approveFundingDto)));
            }

            var funded = await _walletRepository.FundNoobWallet(funding);

            if (!funded)
            {
                return(BadRequest(ResponseMessage.Message("Unable to fund account", "and error was encountered while trying to fund this account", approveFundingDto)));
            }

            await _fundRepository.DeleteFunding(approveFundingDto.FundingId);

            return(Ok(ResponseMessage.Message("Noob account funded", null, approveFundingDto)));
        }