mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Can delete a store
This commit is contained in:
@@ -108,6 +108,34 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(result);
|
return View(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{storeId}/delete")]
|
||||||
|
public async Task<IActionResult> DeleteStore(string storeId)
|
||||||
|
{
|
||||||
|
var store = await _Repo.FindStore(storeId, GetUserId());
|
||||||
|
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")]
|
||||||
|
public async Task<IActionResult> DeleteStorePost(string storeId)
|
||||||
|
{
|
||||||
|
var userId = GetUserId();
|
||||||
|
var store = await _Repo.FindStore(storeId, GetUserId());
|
||||||
|
if(store == null)
|
||||||
|
return NotFound();
|
||||||
|
await _Repo.RemoveStore(storeId, userId);
|
||||||
|
StatusMessage = "Store removed successfully";
|
||||||
|
return RedirectToAction(nameof(ListStores));
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{storeId}")]
|
[Route("{storeId}")]
|
||||||
public async Task<IActionResult> UpdateStore(string storeId)
|
public async Task<IActionResult> UpdateStore(string storeId)
|
||||||
|
|||||||
23
BTCPayServer/Models/ConfirmModel.cs
Normal file
23
BTCPayServer/Models/ConfirmModel.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BTCPayServer.Models
|
||||||
|
{
|
||||||
|
public class ConfirmModel
|
||||||
|
{
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
public string Action
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,6 +83,18 @@ namespace BTCPayServer.Services.Stores
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task RemoveStore(string storeId, string userId)
|
||||||
|
{
|
||||||
|
using(var ctx = _ContextFactory.CreateContext())
|
||||||
|
{
|
||||||
|
var storeUser = await ctx.UserStore.FirstOrDefaultAsync(o => o.StoreDataId == storeId && o.ApplicationUserId == userId);
|
||||||
|
if(storeUser == null)
|
||||||
|
return;
|
||||||
|
ctx.UserStore.Remove(storeUser);
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateStore(StoreData store)
|
public async Task UpdateStore(StoreData store)
|
||||||
{
|
{
|
||||||
using(var ctx = _ContextFactory.CreateContext())
|
using(var ctx = _ContextFactory.CreateContext())
|
||||||
|
|||||||
23
BTCPayServer/Views/Shared/Confirm.cshtml
Normal file
23
BTCPayServer/Views/Shared/Confirm.cshtml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
@model ConfirmModel
|
||||||
|
@{
|
||||||
|
Layout = "_Layout.cshtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<h2 class="section-heading">@Model.Title</h2>
|
||||||
|
<hr class="primary">
|
||||||
|
<p>@Model.Description</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<form method="post">
|
||||||
|
<button type="submit" class="btn btn-info btn-danger" title="Continue">@Model.Action</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<a href="@store.WebSite">@store.WebSite</a>
|
<a href="@store.WebSite">@store.WebSite</a>
|
||||||
}</td>
|
}</td>
|
||||||
<td>@store.Balance</td>
|
<td>@store.Balance</td>
|
||||||
<td><a asp-action="UpdateStore" asp-route-storeId="@store.Id">Settings</a></td>
|
<td><a asp-action="UpdateStore" asp-route-storeId="@store.Id">Settings</a> - <a asp-action="DeleteStore" asp-route-storeId="@store.Id">Remove</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user