Return JsonElement in Response
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ public class WorkflowModel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// داده صفحه جاری
|
/// داده صفحه جاری
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? CurrentPageData { get; set; }
|
public JsonElement? CurrentPageData { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// داده صفحه بعد
|
/// داده صفحه بعد
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Caspian.WorkflowFramework.Models;
|
using Caspian.WorkflowFramework.Models;
|
||||||
|
|
||||||
@@ -32,13 +34,39 @@ public static class ConversionExtensions
|
|||||||
? long.TryParse(dictionary[nameof(workflowModel.UserId)]?.ToString(), out var userId) ? userId : (long?)null
|
? long.TryParse(dictionary[nameof(workflowModel.UserId)]?.ToString(), out var userId) ? userId : (long?)null
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
//workflowModel.CurrentPageData = dictionary.ContainsKey(nameof(workflowModel.CurrentPageData))
|
if (dictionary.TryGetValue(nameof(workflowModel.CurrentPageData), out var currentPageDataObj) &&
|
||||||
// ? (object?)dictionary[nameof(workflowModel.CurrentPageData)]
|
currentPageDataObj is not null)
|
||||||
// : null;
|
{
|
||||||
|
switch (currentPageDataObj)
|
||||||
|
{
|
||||||
|
case JsonElement je:
|
||||||
|
workflowModel.CurrentPageData = je;
|
||||||
|
break;
|
||||||
|
|
||||||
workflowModel.CurrentPageData = dictionary.ContainsKey(nameof(workflowModel.CurrentPageData))
|
case JsonNode node:
|
||||||
? dictionary[nameof(workflowModel.CurrentPageData)]?.ToString()
|
// .NET 6+
|
||||||
: null;
|
workflowModel.CurrentPageData = JsonSerializer.SerializeToElement(node);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case string s:
|
||||||
|
// اگر به صورت string JSON ذخیره شده
|
||||||
|
workflowModel.CurrentPageData = JsonSerializer.Deserialize<JsonElement>(s);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// هر نوع دیگری: serialize و تبدیل به JsonElement
|
||||||
|
workflowModel.CurrentPageData = JsonSerializer.SerializeToElement(currentPageDataObj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
workflowModel.CurrentPageData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//workflowModel.CurrentPageData = dictionary.ContainsKey(nameof(workflowModel.CurrentPageData))
|
||||||
|
// ? dictionary[nameof(workflowModel.CurrentPageData)]?.ToString()
|
||||||
|
// : null;
|
||||||
|
|
||||||
//workflowModel.NextPageData = dictionary.ContainsKey(nameof(workflowModel.NextPageData))
|
//workflowModel.NextPageData = dictionary.ContainsKey(nameof(workflowModel.NextPageData))
|
||||||
// ? (object?)dictionary[nameof(workflowModel.NextPageData)]
|
// ? (object?)dictionary[nameof(workflowModel.NextPageData)]
|
||||||
|
|||||||
Reference in New Issue
Block a user