Clean JSON output for NextPageData and CurrentPageData Normalize NextPageData & CurrentPageData formatting Fix JSON formatting for NextPageData and CurrentPageData Compact JSON for NextPageData and CurrentPageData
220 lines
6.4 KiB
C#
220 lines
6.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using SampleWorkflowWeb.Models;
|
|
using Newtonsoft.Json;
|
|
using SampleWorkflowWeb.Services;
|
|
using SampleWorkflowWeb.Dao;
|
|
using San.MongoLogger;
|
|
using Caspian.WorkflowFramework.Contracts;
|
|
using Elsa.Common.Models;
|
|
using PublishEventModel = Caspian.WorkflowFramework.Models.PublishEventModel;
|
|
using PackageNS = Caspian.WorkflowFramework.Models;
|
|
|
|
namespace SampleWorkflowWeb.Controllers;
|
|
|
|
public class HomeController : Controller, ILoggable
|
|
{
|
|
#region Fields
|
|
private readonly ILogger<HomeController> _logger;
|
|
private readonly ICardService _cardService;
|
|
private readonly IWorkflowService _workflowService;
|
|
#endregion
|
|
|
|
#region Ctor
|
|
public HomeController(ILogger<HomeController> logger,
|
|
ICardService cardService,
|
|
IWorkflowService workflowService)
|
|
{
|
|
_logger = logger;
|
|
_cardService = cardService;
|
|
_workflowService = workflowService;
|
|
}
|
|
#endregion
|
|
|
|
#region Index
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
return View();
|
|
}
|
|
#endregion
|
|
|
|
#region Inquiry
|
|
public async Task<IActionResult> Inquiry()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Inquiry(InquiryViewModel input)
|
|
{
|
|
var response = await _workflowService.InquiryStateAsync(new PackageNS.InquiryStateModel()
|
|
{
|
|
WorkflowInstanceId = input.WorkflowId
|
|
});
|
|
|
|
if (response != null && response.Status == 0)
|
|
{
|
|
return View("InquiryResult", response);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Error", response);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region CardToCard
|
|
public async Task<IActionResult> CardToCard()
|
|
{
|
|
var response = await _workflowService.CreateAndExecuteAsync(new PackageNS.CreateAndExecuteWorkflowModel()
|
|
{
|
|
Name = "CardToCardWorkflow",
|
|
UserId = 114,
|
|
Version = VersionOptions.Published
|
|
});
|
|
|
|
if (response != null && response.Status == 0)
|
|
{
|
|
var form100Input = new Form100ViewModel()
|
|
{
|
|
WorkflowId = response.Data?.InstanceId,
|
|
PageEventName = response.Data?.NextPageEventName
|
|
};
|
|
|
|
//return View(response.Data?.NextPageUrl, form100Input);
|
|
return RedirectToAction(response.Data?.NextPageUrl, form100Input);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Error", response);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Form100
|
|
public async Task<IActionResult> Form100(Form100ViewModel input, string WorkflowId)
|
|
{
|
|
ViewBag.SourceCards = _cardService.GetSourceCardsService();
|
|
ViewBag.DestinationCards = _cardService.GetDestinationCardsService();
|
|
|
|
return View(input);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Form100(Form100ViewModel input)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
ViewBag.SourceCards = _cardService.GetSourceCardsService();
|
|
ViewBag.DestinationCards = _cardService.GetDestinationCardsService();
|
|
|
|
return View(input);
|
|
}
|
|
|
|
var publishModel = new PublishEventModel()
|
|
{
|
|
EventName = input.PageEventName,
|
|
WorkflowInstanceId = input.WorkflowId,
|
|
EventData = System.Text.Json.JsonSerializer.SerializeToElement(input)
|
|
};
|
|
|
|
var response = await _workflowService.PublishEventAsync(publishModel);
|
|
|
|
if (response != null && response.Status == 0)
|
|
{
|
|
var form101Input = new Form101ViewModel()
|
|
{
|
|
From = input.From,
|
|
To = input.To,
|
|
Amount = input.Amount,
|
|
WorkflowId = response.Data?.InstanceId,
|
|
PageEventName = response.Data?.NextPageEventName
|
|
};
|
|
|
|
//return View(response.Data?.NextPageUrl, form101Input);
|
|
return RedirectToAction(response.Data?.NextPageUrl, form101Input);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Error", response);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Form101
|
|
public IActionResult Form101(Form101ViewModel input, string WorkflowId)
|
|
{
|
|
input.FromPan = _cardService.GetCardService(input.From)?.PAN;
|
|
input.FromFullName = _cardService.GetCardOwnerService(input.From);
|
|
|
|
input.ToPan = _cardService.GetCardService(input.To)?.PAN;
|
|
input.ToFullName = _cardService.GetCardOwnerService(input.To);
|
|
|
|
return View(input);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Form101(Form101ViewModel input)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
input.FromPan = _cardService.GetCardService(input.From)?.PAN;
|
|
input.FromFullName = _cardService.GetCardOwnerService(input.From);
|
|
|
|
input.ToPan = _cardService.GetCardService(input.To)?.PAN;
|
|
input.ToFullName = _cardService.GetCardOwnerService(input.To);
|
|
|
|
return View(input);
|
|
}
|
|
|
|
//انتقال
|
|
var result = await _cardService.TransferAsync(input.FromPan, input.ToPan, input.Amount);
|
|
|
|
var publishEventModel = new PublishEventModel()
|
|
{
|
|
EventName = input.PageEventName,
|
|
WorkflowInstanceId = input.WorkflowId,
|
|
EventData = System.Text.Json.JsonSerializer.SerializeToElement(input)
|
|
};
|
|
|
|
var response = await _workflowService.PublishEventAsync(publishEventModel);
|
|
|
|
if (response != null && response.Status == 0)
|
|
{
|
|
var completeInput = new CompleteViewModel()
|
|
{
|
|
From = input.From,
|
|
FromPan = input.FromPan,
|
|
FromFullName = input.FromFullName,
|
|
To = input.To,
|
|
ToPan = input.ToPan,
|
|
ToFullName = input.ToFullName,
|
|
Amount = input.Amount,
|
|
WorkflowId = response.Data?.InstanceId,
|
|
PageEventName = response.Data?.NextPageEventName
|
|
};
|
|
|
|
//return View(response.Data?.NextPageUrl, completeInput);
|
|
return RedirectToAction(response.Data?.NextPageUrl, completeInput);
|
|
}
|
|
else
|
|
{
|
|
return RedirectToAction("Error", response);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Complete
|
|
public IActionResult Complete(CompleteViewModel input)
|
|
{
|
|
return View(input);
|
|
}
|
|
#endregion
|
|
|
|
#region Error
|
|
public IActionResult Error(WorkflowResponse<object> input)
|
|
{
|
|
return View(input);
|
|
}
|
|
#endregion
|
|
}
|