Can delete a store

This commit is contained in:
nicolas.dorier 2017-10-23 22:55:46 +09:00
parent 5f8407b4b1
commit 37c02d2539
5 changed files with 87 additions and 1 deletions

View file

@ -108,6 +108,34 @@ namespace BTCPayServer.Controllers
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]
[Route("{storeId}")]
public async Task<IActionResult> UpdateStore(string storeId)

View 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;
}
}
}

View file

@ -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)
{
using(var ctx = _ContextFactory.CreateContext())

View 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>

View file

@ -42,7 +42,7 @@
<a href="@store.WebSite">@store.WebSite</a>
}</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>
}
</tbody>