BuildModel(EditExchangeExternalServiceDataViewModel viewModel, ExternalServiceData mainModel)
        {
            //current External Service data
            var externalServiceData = mainModel;

            if (!ModelState.IsValid)
            {
                return(null,
                       new EditExchangeExternalServiceDataViewModel(viewModel, await ExchangeService.GetAvailableExchanges()));
            }

            //current External Service data
            externalServiceData.Set((ExchangeExternalServiceData)viewModel);
            var exchangeService = new ExchangeService(externalServiceData);

            if (!await exchangeService.TestAccess())
            {
                ModelState.AddModelError(String.Empty,
                                         "Could not connect with current settings. Transmuter tests against fetching your balance amount from the exchange so you would need to enable that option if available");

                return(null,
                       new EditExchangeExternalServiceDataViewModel(viewModel, await ExchangeService.GetAvailableExchanges()));
            }

            return(externalServiceData, null);
        }
Esempio n. 2
0
        BuildModel(EditExchangeExternalServiceDataViewModel viewModel, ExternalServiceData mainModel)
        {
            //current External Service data
            var externalServiceData = mainModel;

            if (!ModelState.IsValid)
            {
                return(null,
                       new EditExchangeExternalServiceDataViewModel(viewModel, ExchangeService.GetAvailableExchanges()));
            }

            //current External Service data
            externalServiceData.Set((ExchangeExternalServiceData)viewModel);
            var exchangeService = new ExchangeService(externalServiceData);

            if (!await exchangeService.TestAccess())
            {
                ModelState.AddModelError(String.Empty, "Could not connect with current settings");


                return(null,
                       new EditExchangeExternalServiceDataViewModel(viewModel, ExchangeService.GetAvailableExchanges()));
            }

            return(externalServiceData, null);
        }
        public async Task <IActionResult> EditData(string identifier)
        {
            var result = await GetExternalServiceData(identifier);

            if (result.Error != null)
            {
                return(result.Error);
            }

            var client = new ExchangeService(result.Data);

            return(View(new EditExchangeExternalServiceDataViewModel(client.GetData(),
                                                                     ExchangeService.GetAvailableExchanges())));
        }
        public async Task <IActionResult> EditData(string identifier, ExchangeExternalServiceData data)
        {
            var result = await GetExternalServiceData(identifier);

            if (result.Error != null)
            {
                return(result.Error);
            }

            //current External Service data
            var externalServiceData = result.Data;

            if (!ModelState.IsValid)
            {
                return(View(new EditExchangeExternalServiceDataViewModel(data,
                                                                         ExchangeService.GetAvailableExchanges())));
            }

            //current External Service data
            var oldData = externalServiceData.Get <ExchangeExternalServiceData>();

            externalServiceData.Set(data);
            var exchangeService = new ExchangeService(externalServiceData);

            if (!await exchangeService.TestAccess())
            {
                ModelState.AddModelError(String.Empty, "Could not connect with current settings");

                return(View(new EditExchangeExternalServiceDataViewModel(data,
                                                                         ExchangeService.GetAvailableExchanges())));
            }

            await _externalServiceManager.AddOrUpdateExternalServiceData(externalServiceData);

            return(RedirectToAction("EditExternalService", "ExternalServices", new
            {
                id = externalServiceData.Id,
                statusMessage = "Exchange Data updated"
            }));
        }
 protected override async Task <EditExchangeExternalServiceDataViewModel> BuildViewModel(ExternalServiceData data)
 {
     return(new EditExchangeExternalServiceDataViewModel(new ExchangeService(data).GetData(),
                                                         await ExchangeService.GetAvailableExchanges()));
 }
 protected override Task <EditExchangeExternalServiceDataViewModel> BuildViewModel(ExternalServiceData data)
 {
     return(Task.FromResult(new EditExchangeExternalServiceDataViewModel(new ExchangeService(data).GetData(),
                                                                         ExchangeService.GetAvailableExchanges())));
 }