This topic adds an MVC controller to the project and a button (as shown in this image to the AuctionWorx Invoice Details screen.
ShipStationController inherits from AuctionWorxController and resides in the file ShipStationController.cs. The public method, SendInvoiceToShipStation() instantiates a ShipStationClient object then calls its CreateOrder() method.
using RainWorx.FrameWorx.MVC.Helpers; using System.Threading.Tasks; using System.Web.Mvc; namespace RainWorx.FrameWorx.MVC.Controllers { public class ShipStationController : AuctionWorxController { [Authorize(Roles = Strings.Roles.SellerAndAdmin)] public async Task<ActionResult> SendInvoiceToShipStation(int id, bool paid, string returnUrl) { ShipStationClient ssclient = new ShipStationClient(); bool result = await ssclient.CreateOrder(id, paid); if (result) { PrepareSuccessMessage("Sent to ShipStation", MessageType.Message); } else { PrepareErrorMessage("Error sending to ShipStation", MessageType.Message); } return RedirectToAction(Strings.MVC.InvoiceDetailAction, "Account", new { id, returnUrl}); } } }
The button that triggers the ShipStation API call must be added to two partial views in the Account area.
Note: We are dealing here with the Views in the Account view folder, not the versions that appear in the Admin folder.
The first partial view, UnpaidListingInvoice.cshtml displays details of an unpaid invoice. Just below the BackButton partial view (around line 35) add the Send To ShipStation button with the following markup:
@Html.ButtonLink("Send To ShipStation", "SendInvoiceToShipStation", "ShipStation", new { id = Model.ID, paid = false, returnUrl = ViewData[Fields.ReturnUrl] }, new { @class = "btn btn-default btn-xs" })
Notice that Line 2 above passes the paid parameter as false. This value determines the order's status (awaiting_shipment or on_hold) in ShipStation.
The second partial view, PaidListingInvoice.cshtml displays a paid invoice. The button code goes after the BackButton partial view around line 17. This time, the code below indicates that the subsequent order is paid and thus safe to ship.
@Html.ButtonLink("Send To ShipStation", "SendInvoiceToShipStation", "ShipStation", new { id = Model.ID, paid = true, returnUrl = ViewData[Fields.ReturnUrl] }, new { @class = "btn btn-default btn-xs" })
After completing these development steps, you can follow instructions in the next topic to test the implementation.
Copyright © 2002-2022. RainWorx Software. All rights reserved.