Exemple #1
0
        public async Task <IActionResult> SendTransferReplyAsync(
            [FromRoute] string id,
            [FromQuery] TransferReplyMessage.TransferReplyMessageCode code,
            [FromQuery] string destinationAddress)
        {
            var validationErrorsDict = new Dictionary <string, string[]>();

            if (string.IsNullOrWhiteSpace(id))
            {
                validationErrorsDict.Add(nameof(id), new[] { $"{nameof(id)} is required" });
            }

            if (string.IsNullOrWhiteSpace(destinationAddress) && code == TransferReplyMessage.TransferReplyMessageCode.TransferAccepted)
            {
                validationErrorsDict.Add(nameof(destinationAddress), new[] { $"{nameof(destinationAddress)} is required" });
            }

            if (validationErrorsDict.Count > 0)
            {
                return(ValidationProblem(new ValidationProblemDetails(validationErrorsDict)));
            }

            try
            {
                await _transactionsManager.SendTransferReplyAsync(
                    id,
                    destinationAddress,
                    code);
            }
            catch (NullReferenceException)
            {
                return(NotFound());
            }

            var transaction = await _transactionsManager.GetAsync(id);

            return(Ok(_mapper.Map <TransactionDetailsModel>(transaction)));
        }