예제 #1
0
        public async Task <IActionResult> UpdateStore(string storeId)
        {
            var store = await _Repo.FindStore(storeId, GetUserId());

            if (store == null)
            {
                return(NotFound());
            }

            var storeBlob = store.GetStoreBlob();
            var vm        = new StoreViewModel();

            vm.Id        = store.Id;
            vm.StoreName = store.StoreName;
            vm.SetCryptoCurrencies(_ExplorerProvider, store.GetDefaultCrypto());
            vm.SetLanguages(_LangService, storeBlob.DefaultLang);
            vm.StoreWebsite = store.StoreWebsite;
            vm.NetworkFee   = !storeBlob.NetworkFeeDisabled;
            vm.SpeedPolicy  = store.SpeedPolicy;
            AddPaymentMethods(store, vm);
            vm.StatusMessage        = StatusMessage;
            vm.MonitoringExpiration = storeBlob.MonitoringExpiration;
            vm.InvoiceExpiration    = storeBlob.InvoiceExpiration;
            vm.RateMultiplier       = (double)storeBlob.GetRateMultiplier();
            vm.PreferredExchange    = storeBlob.PreferredExchange.IsCoinAverage() ? "coinaverage" : storeBlob.PreferredExchange;
            vm.AllowCoinConversion  = storeBlob.AllowCoinConversion;
            return(View(vm));
        }
예제 #2
0
        public async Task <IActionResult> UpdateStore(string storeId, StoreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.PreferredExchange != null)
            {
                model.PreferredExchange = model.PreferredExchange.Trim().ToLowerInvariant();
            }
            var store = await _Repo.FindStore(storeId, GetUserId());

            if (store == null)
            {
                return(NotFound());
            }
            AddPaymentMethods(store, model);

            bool needUpdate = false;

            if (store.SpeedPolicy != model.SpeedPolicy)
            {
                needUpdate        = true;
                store.SpeedPolicy = model.SpeedPolicy;
            }
            if (store.StoreName != model.StoreName)
            {
                needUpdate      = true;
                store.StoreName = model.StoreName;
            }
            if (store.StoreWebsite != model.StoreWebsite)
            {
                needUpdate         = true;
                store.StoreWebsite = model.StoreWebsite;
            }

            if (store.GetDefaultCrypto() != model.DefaultCryptoCurrency)
            {
                needUpdate = true;
                store.SetDefaultCrypto(model.DefaultCryptoCurrency);
            }
            model.SetCryptoCurrencies(_ExplorerProvider, model.DefaultCryptoCurrency);
            model.SetLanguages(_LangService, model.DefaultLang);

            var blob = store.GetStoreBlob();

            blob.NetworkFeeDisabled   = !model.NetworkFee;
            blob.MonitoringExpiration = model.MonitoringExpiration;
            blob.InvoiceExpiration    = model.InvoiceExpiration;
            blob.DefaultLang          = model.DefaultLang;

            bool newExchange = blob.PreferredExchange != model.PreferredExchange;

            blob.PreferredExchange = model.PreferredExchange;

            blob.SetRateMultiplier(model.RateMultiplier);
            blob.AllowCoinConversion = model.AllowCoinConversion;

            if (store.SetStoreBlob(blob))
            {
                needUpdate = true;
            }

            if (!blob.PreferredExchange.IsCoinAverage() && newExchange)
            {
                using (HttpClient client = new HttpClient())
                {
                    var rate = await client.GetAsync(model.RateSource);

                    if (rate.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        ModelState.AddModelError(nameof(model.PreferredExchange), $"Unsupported exchange ({model.RateSource})");
                        return(View(model));
                    }
                }
            }

            if (needUpdate)
            {
                await _Repo.UpdateStore(store);

                StatusMessage = "Store successfully updated";
            }

            return(RedirectToAction(nameof(UpdateStore), new
            {
                storeId = storeId
            }));
        }