You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.4 KiB
173 lines
6.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Mail;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Model;
|
|
using Newtonsoft.Json;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
namespace zz_api_doccreate_demo
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
//createpac();
|
|
dokumentcreate();
|
|
}
|
|
|
|
private static void createpac()
|
|
{
|
|
DokumentCreate paket = new DokumentCreate();
|
|
paket.Dokumente = new List<APIDokument>();
|
|
paket.Versandstrasse = "No";
|
|
paket.Versand_Direkt = "No";
|
|
paket.Versand_Option = "";
|
|
paket.GAS_Adresse = "";
|
|
paket.Result_OnDoc = "Yes";
|
|
paket.Result_Sender = "No";
|
|
paket.Result_FileType = "WORD";
|
|
paket.ConfirmationMail = "No";
|
|
paket.ConfirmationMailAddress = "";
|
|
|
|
add_dokument(ref paket);
|
|
|
|
add_dokument(ref paket);
|
|
string jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(paket);
|
|
string debugfilename = @"x:\servicepaiket.json";
|
|
System.IO.File.WriteAllText(debugfilename, jsonstring);
|
|
}
|
|
|
|
private static void add_dokument(ref DokumentCreate paket)
|
|
{
|
|
APIDokument apidoc = new APIDokument();
|
|
apidoc.VorlagenTypID = "120";
|
|
apidoc.Partnernr = "1000208";
|
|
apidoc.TGNrErsteller = "stefan hutter lokal";
|
|
apidoc.TGNrVerantwortlich = "stefan hutter lokal";
|
|
apidoc.TGNrUnterschriftLinks = "stefan hutter lokal";
|
|
apidoc.TGNrUnterschriftRechts = "";
|
|
apidoc.OhneUnterschrift = "Yes";
|
|
apidoc.FaksimileUnterschrift = "No";
|
|
apidoc.PrintLogo = "No";
|
|
apidoc.Dokumentdatum = "14.07.2025";
|
|
apidoc.Bezeichnung = "Test API-Dokument";
|
|
apidoc.APIValues = new List<attribute>();
|
|
attribute attr = new attribute();
|
|
attr.Tag = "API Betreff";
|
|
attr.Value = "Musterbrief";
|
|
apidoc.APIValues.Add(attr);
|
|
attribute attr1 = new attribute();
|
|
attr.Tag = "API Anrede";
|
|
attr.Value = "Guten Tag";
|
|
apidoc.APIValues.Add(attr1);
|
|
paket.Dokumente.Add(apidoc);
|
|
|
|
}
|
|
|
|
private static void dokumentcreate()
|
|
{
|
|
DokumentCreate doccreate = new DokumentCreate();
|
|
string debugfilename = @"x:\servicepaiket.json";
|
|
string jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(doccreate);
|
|
jsonstring = System.IO.File.ReadAllText(debugfilename);
|
|
doccreate = Newtonsoft.Json.JsonConvert.DeserializeObject<DokumentCreate>(jsonstring);
|
|
send(ref doccreate);
|
|
}
|
|
|
|
private static void createdoc() {
|
|
//DokumentCreate doccreate = new DokumentCreate();
|
|
//doccreate.APIValues = new List<attribute>();
|
|
|
|
//string debugfilename = @"x:\servicedoc.json";
|
|
//string jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(doccreate);
|
|
//jsonstring = System.IO.File.ReadAllText(debugfilename);
|
|
//doccreate = Newtonsoft.Json.JsonConvert.DeserializeObject<DokumentCreate>(jsonstring);
|
|
//doccreate.Partnernr = "1000208";
|
|
//doccreate.Result_Versandstrasse = "No";
|
|
//doccreate.Result_OnDoc = "Yes";
|
|
//doccreate.Result_Sender = "No";
|
|
//doccreate.Result_FileType = "WORD";
|
|
//doccreate.ConfirmationMail = "No";
|
|
//doccreate.ConfirmationMailAddress = "";
|
|
//doccreate.VorlagenTypID = "120";
|
|
//doccreate.TGNrErsteller = "stefan hutter lokal";
|
|
//doccreate.TGNrVerantwortlich = "stefan hutter lokal";
|
|
//doccreate.TGNrUnterschriftLinks = "stefan hutter lokal";
|
|
//doccreate.TGNrUnterschriftRechts = "";
|
|
//doccreate.OhneUnterschrift = "Yes";
|
|
//doccreate.FaksimileUnterschrift = "No";
|
|
//doccreate.PrintLogo = "No";
|
|
//doccreate.Dokumentdatum = "14.07.2025";
|
|
//doccreate.Bezeichnung = "Test API-Dokument";
|
|
|
|
//attribute at = new attribute();
|
|
//at.Tag = "APIBetreff";
|
|
//at.Value = "Muster-Brief";
|
|
//doccreate.APIValues.Add(at);
|
|
//attribute at1 = new attribute();
|
|
//at1.Tag = "APIAnrede";
|
|
//at1.Value = "Guten Tag";
|
|
//doccreate.APIValues.Add(at1);
|
|
//attribute at2 = new attribute();
|
|
//at2.Tag = "APIInhalt";
|
|
//at2.Value = "Das ist der Dokument-Inhalt";
|
|
//doccreate.APIValues.Add(at2);
|
|
//jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(doccreate);
|
|
//string debugfilename = @"x:\servicedoc.json";
|
|
//System.IO.File.WriteAllText(debugfilename, jsonstring);
|
|
//send(ref doccreate);
|
|
|
|
|
|
}
|
|
|
|
static string send(ref DokumentCreate docCreate)
|
|
{
|
|
string URL = "https://localhost:44334/API/CreateDoks";
|
|
string response;
|
|
string jsonstring = JsonConvert.SerializeObject(docCreate);
|
|
|
|
WebRequest request;
|
|
|
|
var data = Encoding.UTF8.GetBytes(jsonstring);
|
|
request = WebRequest.Create(URL);
|
|
request.ContentLength = data.Length;
|
|
request.ContentType = "application/json";
|
|
request.Method = "POST";
|
|
request.Headers["Authorization"] = "Bearer " + "pZkuG6l6ORCEckqQimPK58PO1A9EnkMtL5oCgRX9WiWnD4xeH7ikGzhWnTBy/vk8J4Iiz8gCSx9uFHA4+DvITG0roO97sk82d/0BCjVlwLWINpXlJfGYEF3X96AdoCQvb3ruwv/tVqEHsSU5aNfyxBAe+EhLTHQ8t7ysgJZWh98=";
|
|
|
|
|
|
try
|
|
{
|
|
|
|
using (Stream requestStream = request.GetRequestStream())
|
|
{
|
|
requestStream.Write(data, 0, data.Length);
|
|
requestStream.Close();
|
|
|
|
using (Stream responseStream = request.GetResponse().GetResponseStream())
|
|
{
|
|
using (var reader = new StreamReader(responseStream))
|
|
{
|
|
response = reader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|