diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index d41b24176..fc9ca6285 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -283,7 +283,7 @@ namespace BTCPayServer.Controllers { CurrencyPair = fetch.Key.ToString(), Error = testResult.Errors.Count != 0, - Rule = testResult.Errors.Count == 0 ? testResult.Rule + " = " + testResult.Value.Value.ToString(CultureInfo.InvariantCulture) + Rule = testResult.Errors.Count == 0 ? testResult.Rule + " = " + testResult.Value.Value.ToString(CultureInfo.InvariantCulture) : testResult.EvaluatedRule }); } @@ -424,6 +424,7 @@ namespace BTCPayServer.Controllers vm.StoreWebsite = store.StoreWebsite; vm.NetworkFee = !storeBlob.NetworkFeeDisabled; vm.SpeedPolicy = store.SpeedPolicy; + vm.CanDelete = _Repo.CanDeleteStores(); AddPaymentMethods(store, vm); vm.MonitoringExpiration = storeBlob.MonitoringExpiration; vm.InvoiceExpiration = storeBlob.InvoiceExpiration; @@ -468,10 +469,8 @@ namespace BTCPayServer.Controllers [HttpPost] [Route("{storeId}")] - public async Task UpdateStore(StoreViewModel model) + public async Task UpdateStore(StoreViewModel model, string command = null) { - AddPaymentMethods(StoreData, model); - bool needUpdate = false; if (StoreData.SpeedPolicy != model.SpeedPolicy) { @@ -511,6 +510,29 @@ namespace BTCPayServer.Controllers { storeId = StoreData.Id }); + + } + + [HttpGet] + [Route("{storeId}/delete")] + public IActionResult DeleteStore(string storeId) + { + return View("Confirm", new ConfirmModel() + { + Action = "Delete this store", + Title = "Delete this store", + Description = "This action is irreversible and will remove all information related to this store. (Invoices, Apps etc...)", + ButtonClass = "btn-danger" + }); + } + + [HttpPost] + [Route("{storeId}/delete")] + public async Task DeleteStorePost(string storeId) + { + await _Repo.DeleteStore(StoreData.Id); + StatusMessage = "Success: Store successfully deleted"; + return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"); } private CoinAverageExchange[] GetSupportedExchanges() diff --git a/BTCPayServer/Controllers/UserStoresController.cs b/BTCPayServer/Controllers/UserStoresController.cs index ed2924dc2..49a6bfc91 100644 --- a/BTCPayServer/Controllers/UserStoresController.cs +++ b/BTCPayServer/Controllers/UserStoresController.cs @@ -35,21 +35,7 @@ namespace BTCPayServer.Controllers _NetworkProvider = networkProvider; _UserManager = userManager; _WalletProvider = walletProvider; - } - [HttpGet] - [Route("{storeId}/delete")] - public IActionResult DeleteStore(string storeId) - { - var store = HttpContext.GetStoreData(); - if (store == null) - return NotFound(); - return View("Confirm", new ConfirmModel() - { - Title = "Delete store " + store.StoreName, - Description = "This store will still be accessible to users sharing it", - Action = "Delete" - }); - } + } [HttpGet] [Route("create")] @@ -63,8 +49,23 @@ namespace BTCPayServer.Controllers get; set; } + [HttpGet] + [Route("{storeId}/me/delete")] + public IActionResult DeleteStore(string storeId) + { + var store = HttpContext.GetStoreData(); + if (store == null) + return NotFound(); + return View("Confirm", new ConfirmModel() + { + Title = "Delete store " + store.StoreName, + Description = "This store will still be accessible to users sharing it", + Action = "Delete" + }); + } + [HttpPost] - [Route("{storeId}/delete")] + [Route("{storeId}/me/delete")] public async Task DeleteStorePost(string storeId) { var userId = GetUserId(); diff --git a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs index 1b86a07c2..6f4f168df 100644 --- a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs @@ -25,6 +25,7 @@ namespace BTCPayServer.Models.StoreViewModels } + public bool CanDelete { get; set; } public string Id { get; set; } [Display(Name = "Store Name")] [Required] diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index 05ec93de0..8acdc066e 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -188,5 +188,13 @@ namespace BTCPayServer.Services.Stores return true; } } + + public bool CanDeleteStores() + { + using (var ctx = _ContextFactory.CreateContext()) + { + return ctx.Database.SupportDropForeignKey(); + } + } } } diff --git a/BTCPayServer/Views/Stores/UpdateStore.cshtml b/BTCPayServer/Views/Stores/UpdateStore.cshtml index 5817f9822..35018963a 100644 --- a/BTCPayServer/Views/Stores/UpdateStore.cshtml +++ b/BTCPayServer/Views/Stores/UpdateStore.cshtml @@ -130,6 +130,16 @@ Available placeholders are: {StoreName}, {ItemDescription} and {OrderId}

+ @if(Model.CanDelete) + { +
+
Other actions...
+

Click here to see more actions

+ +
+ }