Add project files.
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SampleWorkflowWeb.Models;
|
||||
using Newtonsoft.Json;
|
||||
using SampleWorkflowWeb.Services;
|
||||
using SampleWorkflowWeb.Dao;
|
||||
using 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 = JsonConvert.SerializeObject(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 = JsonConvert.SerializeObject(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
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
using SampleWorkflowWeb.Models;
|
||||
using SampleWorkflowWeb.Models.Transfer;
|
||||
using SampleWorkflowWeb.Services;
|
||||
using Caspian.WorkflowFramework.Contracts;
|
||||
using PackageNS = Caspian.WorkflowFramework.Models;
|
||||
using Elsa.Common.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MongoLogger;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace SampleWorkflowWeb.Controllers
|
||||
{
|
||||
public class TransferController : Controller, ILoggable
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly ICardService _cardService;
|
||||
private readonly IWorkflowService _workflowService;
|
||||
#endregion
|
||||
|
||||
#region Ctor
|
||||
public TransferController(ILogger<HomeController> logger,
|
||||
ICardService cardService,
|
||||
IWorkflowService workflowService)
|
||||
{
|
||||
_logger = logger;
|
||||
_cardService = cardService;
|
||||
_workflowService = workflowService;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Index
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TransferAmount
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> TransferAmount(long userId)
|
||||
{
|
||||
var response = await _workflowService.CreateAndExecuteAsync(new PackageNS.CreateAndExecuteWorkflowModel()
|
||||
{
|
||||
Name = "TransferWorkflow",
|
||||
UserId = userId,
|
||||
Version = VersionOptions.Published
|
||||
});
|
||||
|
||||
if (response != null && response.Status == 0)
|
||||
{
|
||||
var input = new SelectionViewModel()
|
||||
{
|
||||
WorkflowId = response.Data?.InstanceId,
|
||||
PageEventName = response.Data?.NextPageEventName
|
||||
};
|
||||
|
||||
|
||||
|
||||
HttpContext.Session.SetObject("SelectionSession", input);
|
||||
|
||||
//return View(response.Data?.NextPageUrl, input);
|
||||
return RedirectToAction(response.Data?.NextPageUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Error", response);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Selection
|
||||
public async Task<IActionResult> Selection()
|
||||
{
|
||||
// Retrieve from session
|
||||
var model = HttpContext.Session.GetObject<SelectionViewModel>("SelectionSession");
|
||||
HttpContext.Session.Remove("SelectionSession");
|
||||
|
||||
ViewBag.SourceCards = _cardService.GetSourceCardsService();
|
||||
ViewBag.DestinationCards = _cardService.GetDestinationCardsService();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Selection(SelectionViewModel input)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
ViewBag.SourceCards = _cardService.GetSourceCardsService();
|
||||
ViewBag.DestinationCards = _cardService.GetDestinationCardsService();
|
||||
|
||||
return View(input);
|
||||
}
|
||||
|
||||
var publishModel = new PackageNS.PublishEventModel()
|
||||
{
|
||||
EventName = input.PageEventName,
|
||||
WorkflowInstanceId = input.WorkflowId,
|
||||
EventData = JsonConvert.SerializeObject(input)
|
||||
};
|
||||
|
||||
var response = await _workflowService.PublishEventAsync(publishModel);
|
||||
|
||||
if (response != null && response.Status == 0)
|
||||
{
|
||||
if (response.Data?.NextPageUrl == "Confirm")
|
||||
{
|
||||
var fromPan = _cardService.GetCardService(input.From)?.PAN;
|
||||
var fromFullName = _cardService.GetCardOwnerService(input.From);
|
||||
|
||||
var toPan = _cardService.GetCardService(input.To)?.PAN;
|
||||
var toFullName = _cardService.GetCardOwnerService(input.To);
|
||||
|
||||
var confirmViewModel = new ConfirmViewModel()
|
||||
{
|
||||
From = input.From,
|
||||
FromPan = fromPan,
|
||||
FromFullName = fromFullName,
|
||||
To = input.To,
|
||||
ToPan = toPan,
|
||||
ToFullName = toFullName,
|
||||
Amount = input.Amount,
|
||||
PersonType = input.PersonType,
|
||||
WorkflowId = response.Data?.InstanceId,
|
||||
PageEventName = response.Data?.NextPageEventName
|
||||
};
|
||||
|
||||
HttpContext.Session.SetObject("ConfirmSession", confirmViewModel);
|
||||
|
||||
//return View(response.Data?.NextPageUrl, confirmViewModel);
|
||||
return RedirectToAction(response.Data?.NextPageUrl);
|
||||
}
|
||||
else if (response.Data?.NextPageUrl == "Cartable")
|
||||
{
|
||||
var viewModel = new CartableViewModel()
|
||||
{
|
||||
From = input.From,
|
||||
To = input.To,
|
||||
Amount = input.Amount,
|
||||
PersonType = input.PersonType,
|
||||
WorkflowId = response.Data?.InstanceId,
|
||||
PageEventName = response.Data?.NextPageEventName
|
||||
};
|
||||
|
||||
HttpContext.Session.SetObject("CartableSession", viewModel);
|
||||
|
||||
return RedirectToAction(response.Data?.NextPageUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewBag.SourceCards = _cardService.GetSourceCardsService();
|
||||
ViewBag.DestinationCards = _cardService.GetDestinationCardsService();
|
||||
|
||||
return View(input);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return RedirectToAction("Error", response);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Cartable
|
||||
public async Task<IActionResult> Cartable()
|
||||
{
|
||||
// Retrieve from session
|
||||
var model = HttpContext.Session.GetObject<CartableViewModel>("CartableSession");
|
||||
HttpContext.Session.Remove("CartableSession");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Cartable(CartableViewModel input)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
//ViewBag.SourceCards = _cardService.GetSourceCardsService();
|
||||
//ViewBag.DestinationCards = _cardService.GetDestinationCardsService();
|
||||
|
||||
return View(input);
|
||||
}
|
||||
|
||||
var publishModel = new PackageNS.PublishEventModel()
|
||||
{
|
||||
EventName = input.PageEventName,
|
||||
WorkflowInstanceId = input.WorkflowId,
|
||||
EventData = JsonConvert.SerializeObject(input)
|
||||
};
|
||||
|
||||
var response = await _workflowService.PublishEventAsync(publishModel);
|
||||
|
||||
if (response != null && response.Status == 0)
|
||||
{
|
||||
var fromPan = _cardService.GetCardService(input.From)?.PAN;
|
||||
var fromFullName = _cardService.GetCardOwnerService(input.From);
|
||||
|
||||
var toPan = _cardService.GetCardService(input.To)?.PAN;
|
||||
var toFullName = _cardService.GetCardOwnerService(input.To);
|
||||
|
||||
var viewModel = new ConfirmViewModel()
|
||||
{
|
||||
From = input.From,
|
||||
FromPan = fromPan,
|
||||
FromFullName = fromFullName,
|
||||
To = input.To,
|
||||
ToPan = toPan,
|
||||
ToFullName = toFullName,
|
||||
Amount = input.Amount,
|
||||
PersonType = input.PersonType,
|
||||
WorkflowId = response.Data?.InstanceId,
|
||||
PageEventName = response.Data?.NextPageEventName
|
||||
};
|
||||
|
||||
HttpContext.Session.SetObject("ConfirmSession", viewModel);
|
||||
|
||||
return RedirectToAction(response.Data?.NextPageUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Error", response);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Confirm
|
||||
public async Task<IActionResult> Confirm()
|
||||
{
|
||||
// Retrieve from session
|
||||
var model = HttpContext.Session.GetObject<ConfirmViewModel>("ConfirmSession");
|
||||
HttpContext.Session.Remove("ConfirmSession");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Confirm(ConfirmViewModel input)
|
||||
{
|
||||
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);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View(input);
|
||||
}
|
||||
|
||||
//انتقال
|
||||
var result = await _cardService.TransferAsync(input.FromPan, input.ToPan, input.Amount);
|
||||
|
||||
var publishModel = new PackageNS.PublishEventModel()
|
||||
{
|
||||
EventName = input.PageEventName,
|
||||
WorkflowInstanceId = input.WorkflowId,
|
||||
EventData = JsonConvert.SerializeObject(input)
|
||||
};
|
||||
|
||||
var response = await _workflowService.PublishEventAsync(publishModel);
|
||||
|
||||
if (response != null && response.Status == 0)
|
||||
{
|
||||
var receiptInput = new ReceiptViewModel()
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
HttpContext.Session.SetObject("ReceiptSession", receiptInput);
|
||||
|
||||
return RedirectToAction(response.Data?.NextPageUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Error", response);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Confirm
|
||||
public async Task<IActionResult> Receipt()
|
||||
{
|
||||
// Retrieve from session
|
||||
var model = HttpContext.Session.GetObject<ReceiptViewModel>("ReceiptSession");
|
||||
HttpContext.Session.Remove("ReceiptSession");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Error
|
||||
public IActionResult Error(WorkflowResponse<object> input)
|
||||
{
|
||||
return View(input);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user