From 95d746504d7b371fc00611c9d6438ef0365ee905 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Fri, 3 May 2019 14:54:40 -0500 Subject: [PATCH] Changing invoice state and updating display from js --- .../Controllers/InvoiceController.UI.cs | 53 ++++++----------- .../Views/Invoice/ListInvoices.cshtml | 58 +++++++++++++------ 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 3ad35738f..260355592 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -673,61 +673,46 @@ namespace BTCPayServer.Controllers } } - [HttpGet] - [Route("invoices/{invoiceId}/changestate/{newState}")] - [Authorize(AuthenticationSchemes = Policies.CookieAuthentication)] - [BitpayAPIConstraint(false)] - public IActionResult ChangeInvoiceState(string invoiceId, string newState) - { - if (newState == "invalid") - { - return View("Confirm", new ConfirmModel() - { - Action = "Make invoice invalid", - Title = "Change invoice state", - Description = $"You will transition the state of this invoice to \"invalid\", do you want to continue?", - }); - } - else if (newState == "complete") - { - return View("Confirm", new ConfirmModel() - { - Action = "Make invoice complete", - Title = "Change invoice state", - Description = $"You will transition the state of this invoice to \"complete\", do you want to continue?", - ButtonClass = "btn-primary" - }); - } - else - return NotFound(); - } - [HttpPost] [Route("invoices/{invoiceId}/changestate/{newState}")] [Authorize(AuthenticationSchemes = Policies.CookieAuthentication)] [BitpayAPIConstraint(false)] - public async Task ChangeInvoiceStateConfirm(string invoiceId, string newState) + public async Task ChangeInvoiceState(string invoiceId, string newState) { var invoice = (await _InvoiceRepository.GetInvoices(new InvoiceQuery() { InvoiceId = invoiceId, UserId = GetUserId() })).FirstOrDefault(); + + var model = new InvoiceStateChangeModel(); if (invoice == null) - return NotFound(); + { + model.NotFound = true; + return NotFound(model); + } + + if (newState == "invalid") { await _InvoiceRepository.UpdatePaidInvoiceToInvalid(invoiceId); _EventAggregator.Publish(new InvoiceEvent(invoice, 1008, InvoiceEvent.MarkedInvalid)); - StatusMessage = "Invoice marked invalid"; + model.StatusString = new InvoiceState("invalid", "marked").ToString(); } else if (newState == "complete") { await _InvoiceRepository.UpdatePaidInvoiceToComplete(invoiceId); _EventAggregator.Publish(new InvoiceEvent(invoice, 2008, InvoiceEvent.MarkedCompleted)); - StatusMessage = "Invoice marked complete"; + model.StatusString = new InvoiceState("complete", "marked").ToString(); } - return RedirectToAction(nameof(ListInvoices)); + + return Json(model); + } + + public class InvoiceStateChangeModel + { + public bool NotFound { get; set; } + public string StatusString { get; set; } } [TempData] diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 27ba44da9..057065f74 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -91,7 +91,7 @@ OrderId InvoiceId - Status + Status Amount Actions @@ -119,23 +119,25 @@ @if (invoice.CanMarkStatus) { - -