-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
48 lines (44 loc) · 1.29 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Data.SqlClient;
using Dapper;
using System.Data;
using System.Linq;
namespace azure_sql_todo_backend_func_dotnet
{
public static class Utils
{
public static void EnrichJsonResult(HttpRequest req, JToken result, string test)
{
var baseUrl = req.Scheme + "://" + req.Host + $"/api/todo/{test}";
var InjectUrl = new Action<JObject>(i =>
{
if (i != null)
{
var itemId = i["id"]?.Value<int>();
if (itemId != null) i["url"] = baseUrl + $"/{itemId}";
}
});
switch (result.Type)
{
case JTokenType.Object:
InjectUrl(result as JObject);
break;
case JTokenType.Array:
foreach (var i in result)
{
InjectUrl(i as JObject);
}
break;
}
}
}
}