55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Net.Mime;
|
|
using System.Text.Json;
|
|
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
|
|
namespace Sufi.Demo.PeopleDirectory.UI.Server.Controllers.v1
|
|
{
|
|
[ApiVersion(1.0)]
|
|
public class BeaconController : BaseApiController<BeaconController>
|
|
{
|
|
[HttpGet]
|
|
[HttpPost]
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var beaconData = new Dictionary<string, string>();
|
|
|
|
if (Request.Method == "GET")
|
|
{
|
|
foreach (var param in Request.Query)
|
|
{
|
|
beaconData[param.Key] = param.Value.ToString();
|
|
}
|
|
}
|
|
else if (Request.Method == "POST")
|
|
{
|
|
var contentType = Request.ContentType?.ToLower();
|
|
|
|
if (contentType?.Contains(MediaTypeNames.Application.Json) == true)
|
|
{
|
|
using var reader = new StreamReader(Request.Body);
|
|
var body = await reader.ReadToEndAsync();
|
|
var jsonData = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(body)!;
|
|
|
|
foreach (var kvp in jsonData)
|
|
{
|
|
beaconData[kvp.Key] = kvp.Value.ToString();
|
|
}
|
|
}
|
|
else if (contentType?.Contains(MediaTypeNames.Application.FormUrlEncoded) == true)
|
|
{
|
|
var form = await Request.ReadFormAsync();
|
|
foreach (var kvp in form)
|
|
{
|
|
beaconData[kvp.Key] = kvp.Value.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|