Untitled

 avatar
unknown
plain_text
a year ago
4.9 kB
20
Indexable
private async Task<(string, bool)> ProcessIALine(VoliVendorInvoiceJournal inv, string journalNumber, int Linenumber)
        {
            var newbase = "invoiceallocation/data;journalnumber=" + journalNumber + ";linenumber=" + Linenumber;
            HttpResponseMessage response = await client.GetAsync(newbase);
            try
            {
                if (response.IsSuccessStatusCode)
                {
                    var glRespStr = await response.Content.ReadAsStringAsync();    // Read record
                    JObject glRespJson = JObject.Parse(glRespStr);              // parse to JSON object
                    JObject glRespLinksCard = (JObject)glRespJson["panes"]["card"]["links"]; // Find links in JSON object
                    JObject glTable = (JObject)glRespJson["panes"]["table"]["links"]; // Find links in JSON object
                    var tableinserturl = glTable["action:add"]["href"]; // initialize link
                    var tablecreatvieurl = glTable["action:create"]["href"]; // creation link
                    var concurrencyControl = glRespJson["panes"]["table"]["meta"]["concurrencyControl"].Value<string>();
                    // input linevalues
                    foreach (var line in inv.VoliInvoiceAllocationLine)
                    {
                        client.DefaultRequestHeaders.Add("Maconomy-Concurrency-Control", concurrencyControl);
                        var tableresponse = await client.PostAsync(tableinserturl.ToString(), null);
                        var tableInitStr = await tableresponse.Content.ReadAsStringAsync();
                        JObject tableInitJson = JObject.Parse(tableInitStr);
                        if (line.Purchaselinetype != null)
                            tableInitJson["data"]["purchaselinetype"] = line.Purchaselinetype;
                        if (line.Localaccountnumber != null)
                            tableInitJson["data"]["LocalAccountNumber"] = line.Localaccountnumber;
                        if (line.Accountnumber != null)
                            tableInitJson["data"]["accountnumber"] = line.Accountnumber;
                        if (line.Jobnumber != null)
                            tableInitJson["data"]["jobnumber"] = line.Jobnumber;
                        if (line.Taskname != null)
                            tableInitJson["data"]["taskname"] = line.Taskname;
                        if (line.Numberof != null)
                            tableInitJson["data"]["numberof"] = line.Numberof;
                        else
                            tableInitJson["data"]["numberof"] = 1;
                        if (line.Employeenumber != null)
                            tableInitJson["data"]["EmployeeNumber"] = line.Employeenumber;
                        if (line.Entrytext != null)
                            tableInitJson["data"]["entrytext"] = line.Entrytext;
                        if (line.Unitpricecurrency != null)
                            tableInitJson["data"]["UnitPriceCurrency"] = line.Unitpricecurrency * 100;
                        if (line.Vatcurrency != null)
                            tableInitJson["data"]["vatcurrency"] = line.Vatcurrency * (double)100;
                        if (line.Financevatcode != null)
                            tableInitJson["data"]["financevatcode"] = line.Financevatcode;
                        if (line.ExecutingDepartment != null)
                            tableInitJson["data"]["entityname"] = line.ExecutingDepartment;
                        if (line.ResponsibleDepartment != null)
                            tableInitJson["data"]["locationname"] = line.ResponsibleDepartment;
                        if (line.Specification1name != null)
                            tableInitJson["data"]["specification1name"] = line.Specification1name;
                        if (line.FunctionalArea != null)
                            tableInitJson["data"]["specification4name"] = line.FunctionalArea;
                        if (line.Specification5name != null)
                            tableInitJson["data"]["specification5name"] = line.Specification5name;
                        if (line.Specification6name != null)
                            tableInitJson["data"]["specification6name"] = line.Specification6name;
                        concurrencyControl = tableInitJson["meta"]["concurrencyControl"].Value<string>();
                        client.DefaultRequestHeaders.Remove("Maconomy-Concurrency-Control");
                        client.DefaultRequestHeaders.Add("Maconomy-Concurrency-Control", concurrencyControl);
                        HttpResponseMessage responseTableJournal = await client.PostAsJsonAsync(tablecreatvieurl.ToString(), tableInitJson);
                    }
                }
            }
        }
    }
Editor is loading...
Leave a Comment