public void ConvertTest_DestinationNull()
        {
            Transaction source = new Transaction()
            {
                Amount         = 123.45M,
                Date           = DateTime.Now,
                Description    = "Testing...",
                RollingBalance = 543.21M,
                Type           = "Credit"
            };

            TransactionVm destination = null;

            TransactionVm expected = new TransactionVm()
            {
                AmountText         = "£123.45",
                DateText           = DateTime.Now.ToString("dd MMM y", CultureInfo.CurrentCulture),
                Description        = "Testing...",
                RollingBalanceText = "£543.21"
            };

            TransactionVm result = _converter.Convert(source, destination, null);

            Assert.IsTrue(Utilities.DeepCompare(expected, result));
        }
        public void ConvertTest_SourceNull()
        {
            Transaction   source      = null;
            TransactionVm destination = new TransactionVm();
            TransactionVm expected    = null;

            TransactionVm result = _converter.Convert(source, destination, null);

            Assert.AreEqual(expected, result);
        }
        public TransactionPage()
        {
            _blockchainService = new UNBlockchainService();
            InitializeComponent();

            EntryPrivateKey.Text = Application.Current.Properties["Key"].ToString();
            ButtonSend.Clicked  += async(sender, args) =>
            {
                Loading.IsRunning = true;
                try
                {
                    var privateKey = EntryPrivateKey.Text;
                    var address    = EntryAddress.Text;
                    var amount     = Convert.ToDecimal(EntryAmount.Text);

                    var transferVm = new TransactionVm
                    {
                        Secret    = privateKey,
                        ToAddress = address,
                        Amount    = amount
                    };


                    var result = await _blockchainService.Transfer(transferVm);

                    if (result == "No ha sido posible ejecutar la transacción.")
                    {
                        await DisplayAlert("Error", result, "OK");
                    }
                    else
                    {
                        await DisplayAlert("Éxito", result, "OK");

                        var newBalance = await _blockchainService.GetAccountBalance(Application.Current.Properties["Address"].ToString());

                        Application.Current.Properties["Balance"] = "$ " + newBalance;


                        Application.Current.MainPage = new MasterPage();
                    }
                    Loading.IsRunning = false;
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Error", "Ha ocurrido un error inesperado", "OK");

                    Loading.IsRunning = false;
                }
            };
        }
        public async Task <IActionResult> Transfer([FromBody] TransactionVm transactionVm)
        {
            try
            {
                var result = await _unBlockchainService.Transfer(transactionVm.Secret, transactionVm.ToAddress,
                                                                 transactionVm.Amount);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.HResult, ex.InnerException == null ? ex.Message : ex.InnerException.Message);
                return(BadRequest("Ha ocurrido un error inesperado."));
            }
        }
示例#5
0
        public async Task <string> Transfer(TransactionVm transactionVm)
        {
            var json     = JsonConvert.SerializeObject(transactionVm);
            var content  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await _client.PostAsync("Blockchain/Transfer", content);

            if (response.IsSuccessStatusCode)
            {
                var result = JsonConvert.DeserializeObject <ResultVm>(response.Content.ReadAsStringAsync().Result);
                return(result.Result);
            }
            else
            {
                return("No ha sido posible ejecutar la transacción.");
            }
        }
        public async Task <IActionResult> Index()
        {
            var projects = await Mediator.Send(new GetFinancialProjectQuery());

            var model = new TransactionVm
            {
                TransactionPartialModel = new TransactionPartialModel
                {
                    PayedTransaction    = await Mediator.Send(new GetPayedTransactionQuery()),
                    ReceivedTransaction = await Mediator.Send(new GetReceivedTransactionQuery()),
                },
                Projects = projects.FinancialProjects.ToList()
            };

            return(View(model));
        }
        public async Task <IActionResult> TransactionPartialByProject(string id)
        {
            var projects = await Mediator.Send(new GetFinancialProjectQuery());

            var model = new TransactionVm
            {
                SelectedProject         = id,
                TransactionPartialModel = new TransactionPartialModel
                {
                    PayedTransaction    = await Mediator.Send(new GetPayedTransactionByProjectQuery { FinancialProjectId = id }),
                    ReceivedTransaction = await Mediator.Send(new GetReceivedTransactionByProjectQuery { FinancialProjectId = id })
                },
                Projects = projects.FinancialProjects.ToList()
            };

            return(PartialView("Partial/IndexPartial", model));
        }
        public void PerformTransaction(TransactionVm model)
        {
            var organizationExists = _aplicationDbContext.Organizations.SingleOrDefault(p => p.Id == model.OrganizationId);

            if (organizationExists == null)
            {
                throw new Exception("Организации с таким номером не имеется");
            }

            Transaction transaction = new Transaction()
            {
                OrganizationId  = model.OrganizationId,
                Sum             = model.Sum,
                TransactionDate = DateTime.Now,
                TransactionType = model.TransactionType,
                Description     = model.Description
            };

            _aplicationDbContext.Transactions.Add(transaction);
            _aplicationDbContext.SaveChanges();
        }
 public bool Create(TransactionVm m)
 {
     try
     {
         var save = context.CR_Transactions.Add(new CR_Transactions()
         {
             Status          = m.Status.ToString(),
             AccountId       = m.accountId,
             Amount          = m.Amount,
             TransactionType = m.TransactionType.ToString(),
             DateCreated     = DateTime.UtcNow,
         });
         context.SaveChanges();
         savedId = save.Id;
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }