Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetSignedContracts.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
11using Waher.Script;
15
17{
22 {
27 : base("Legal/GetSignedContracts",
28 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
29 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
30 {
31 }
32
33 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(GetSignedContracts).Namespace + ".JSON.GetSignedContracts.req");
34 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(GetSignedContracts).Namespace + ".XML.GetSignedContracts.req");
35
44 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
45 {
47
48 int Offset = 0;
49 int MaxCount = int.MaxValue;
50
51 if (Parameters.TryGetValue("POffset", out IElement E) && !(E is null) &&
52 E.AssociatedObjectValue is double d)
53 {
54 Offset = (int)d;
55 }
56
57 if (Parameters.TryGetValue("PMaxCount", out E) && !(E is null) &&
58 E.AssociatedObjectValue is double d2)
59 {
60 MaxCount = (int)d2;
61 }
62
63 List<NamedDictionary<string, object>> Result = new List<NamedDictionary<string, object>>();
64 IEnumerable<ContractSignature> Signatures = await Database.Find<ContractSignature>(Offset, MaxCount,
65 new FilterFieldEqualTo("BareJid", User.Account.UserName + "@" + Gateway.Domain), "LegalId", "ContractId");
66
67 foreach (ContractSignature Signature in Signatures)
68 {
69 Result.Add(new NamedDictionary<string, object>("ContractSignature", AgentNamespace)
70 {
71 { "contractId", Signature.ContractId.Value },
72 { "legalId", Signature.LegalId.Value }
73 });
74 }
75
76 await Response.Return(new NamedDictionary<string, object>("ContractSignaturesResponse", AgentNamespace)
77 {
78 { "Signatures", Result.ToArray() }
79 });
80 }
81 }
82}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:96
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static CaseInsensitiveString Domain
Domain name.
Definition: Gateway.cs:2354
Represents an HTTP request.
Definition: HttpRequest.cs:18
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:247
This filter selects objects that have a named field equal to a given value.
Class managing a script expression.
Definition: Expression.cs:39
CaseInsensitiveString UserName
User Name of account
Definition: Account.cs:99
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Basic interface for all types of elements.
Definition: IElement.cs:20