public EditExchangeExternalServiceDataViewModel(ExchangeExternalServiceData serviceData,
                                                 IEnumerable <IExchangeAPI> exchangeApis)
 {
     OverrideUrl  = serviceData.OverrideUrl;
     ExchangeName = serviceData.ExchangeName;
     PublicKey    = serviceData.PublicKey;
     PassPhrase   = serviceData.PassPhrase;
     PrivateKey   = serviceData.PrivateKey;
     LastCheck    = serviceData.LastCheck;
     PairedDate   = serviceData.PairedDate;
     Exchanges    = new SelectList(exchangeApis, nameof(IExchangeAPI.Name), nameof(IExchangeAPI.Name),
                                   ExchangeName);
 }
        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"
            }));
        }