Files
Epi2Exchange/Epi2Exchange/Model/ContactDetailPayload.cs
2025-02-12 09:46:23 +01:00

125 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using RestSharp;
namespace Epi2Exchange.Model
{
class ContactDetailPayload
{
[JsonProperty("primary_key")]
public String PrimaryKey { get; set; }
[JsonProperty("customer_no")]
public String CustomerNumber { get; set; }
[JsonProperty("supplier_no")]
public String SupplierNumber { get; set; }
[JsonProperty("name")]
public String Name { get; set; }
[JsonProperty("salutation")]
public String salutation { get; set; }
[JsonProperty("is_customer")]
public bool IsCustomer { get; set; }
[JsonProperty("is_supplier")]
public bool IsSupplier { get; set; }
[JsonProperty("address")]
public ContactDetailAddress address { get; set; }
[JsonProperty("communication")]
public List<ContactDetailCommunication> communication { get; set; }
[JsonProperty("contact_person")]
public List<ContactPerson> contactPerson { get; set; }
}
class ContactDetailAddress
{
[JsonProperty("primary_key")]
public String PrimaryKey { get; set; }
[JsonProperty("postal_code")]
public String PostalCode { get; set; }
[JsonProperty("street")]
public String Street { get; set; }
[JsonProperty("city")]
public String City { get; set; }
[JsonProperty("country")]
public String Country { get; set; }
[JsonProperty("federal_state")]
public String FederalState { get; set; }
}
class ContactDetailCommunication
{
[JsonProperty("primary_key")]
public String PrimaryKey { get; set; }
[JsonProperty("uplink")]
public String ContactData { get; set; }
[JsonProperty("type")]
public String Type { get; set; }
}
class ContactPerson
{
RestClient epirentserver;
[JsonProperty("primary_key")]
public String PrimaryKey { get; set; }
public ContactPersonDetail ContactPersonDetail { get; set; }
public ContactPerson()
{
epirentserver = new RestClient("http://" + Properties.Settings.Default.EpiServer + ":" + Properties.Settings.Default.EpiPort);
}
public void setContactPersonDetail()
{
ContactPersonDetail = GetContactPersonDetailFromJson(getContactPersonDetailJson());
}
public String getContactPersonDetailJson()
{
RestRequest request = new RestRequest("/v1/cperson/" + PrimaryKey + "/filter?ia=1&cl=" + Properties.Settings.Default.EpiMandant, Method.GET);
request.AddHeader("X-EPI-NO-SESSION", "True");
request.AddHeader("X-EPI-ACC-TOK", Properties.Settings.Default.EpiToken);
request.RequestFormat = DataFormat.Json;
return epirentserver.ExecuteAsGet(request, "GET").Content;
}
public Model.ContactPersonDetail GetContactPersonDetailFromJson(String ContactDetailJson)
{
Model.ContactPersonDetail contactDetail = JsonConvert.DeserializeObject<Model.ContactPersonDetail>(ContactDetailJson);
return contactDetail;
}
}
}