Exemplo n.º 1
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateOutgoingTransactionRequestModel model)
        {
            var originatorPlaceOfBirthCountry =
                Country
                .List
                .Single(x => x.Value.Name == model.OriginatorPlaceOfBirth.Country)
                .Value;

            var originatorPostalAddressCountry =
                Country
                .List
                .Single(x => x.Value.Name == model.OriginatorPostalAddress.Country)
                .Value;

            if (model.Asset != "ETH" && model.Asset != "BTC")
            {
                throw new InvalidOperationException("Asset not recognized.");
            }

            var asset = model.Asset == "ETH" ? VirtualAssetType.ETH : VirtualAssetType.BTC;

            var transaction = await _transactionsManager.CreateOutgoingTransactionAsync(
                model.OriginatorFullName,
                model.OriginatorVaan,
                new Core.Models.PlaceOfBirth
            {
                Country = originatorPlaceOfBirthCountry,
                Date    = model.OriginatorPlaceOfBirth.Date,
                Town    = model.OriginatorPlaceOfBirth.Town
            },
                new Core.Models.PostalAddress
            {
                Country     = originatorPostalAddressCountry,
                AddressLine = model.OriginatorPostalAddress.AddressLine,
                Building    = model.OriginatorPostalAddress.Building,
                PostCode    = model.OriginatorPostalAddress.PostCode,
                Street      = model.OriginatorPostalAddress.Street,
                Town        = model.OriginatorPostalAddress.Town
            },
                model.BeneficiaryFullName,
                model.BeneficiaryVaan,
                asset,
                model.Amount);

            return(Ok(transaction));
        }