Пример #1
0
        public IActionResult OnPost()
        {
            if (InputFile == null)
            {
                return(Page());
            }
            if (!InputFile.FileName.EndsWith(".xml"))
            {
                return(Page());
            }
            else
            {
                var    data   = InputFile.ToByteArray();
                Stream stream = new MemoryStream(data);

                XmlDocument doc = new XmlDocument();
                doc.Load(stream);

                string json = JsonConvert.SerializeXmlNode(doc);

                var rawResponse = JsonConvert.DeserializeObject <Rootobject>(json);

                var test = rawResponse.eExact.Accounts.Account.ToList();

                var list = m_context.Company.ToList();

                foreach (var Company in test)
                {
                    var result = list.FirstOrDefault(x => x.Name == Company.Name);
                    if (result == null)
                    {
                        m_exactOnlineService.AddCompany(Company.Name, Company.Address.AddressLine1, Company.Email, Company.code, Company.HomePage, Company.Phone, Company.Address.PostalCode, Company.Address.Country, Company.Address.City);
                    }
                    else
                    {
                        var updateCompany = m_context.Company.FirstOrDefault(x => x.Name == Company.Name);

                        updateCompany.Phone      = Company.Phone;
                        updateCompany.Address    = Company.Address.AddressLine1;
                        updateCompany.Email      = Company.Email;
                        updateCompany.Code       = Company.code;
                        updateCompany.Postalcode = Company.Address.PostalCode;
                        m_context.SaveChanges();
                    }
                }

                return(RedirectToPage("../Admin/AdminCompanies"));
            }
        }
Пример #2
0
        public void GetAccountGUID(string Token, int Division)
        {
            using (var client = new HttpClient())
            {
                //set our headers
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);

                var method  = new HttpMethod("GET");
                var request = new HttpRequestMessage(method, "https://start.exactonline.be/api/v1/" + Division + "/crm/Accounts?$filter=Status eq'C'");

                //Working API calls
                //Juiste !!!
                //crm/Accounts?$filter=Status eq'C'


                ///api/v1/{division}/crm/Contacts?$filter=ID eq guid'00000000-0000-0000-0000-000000000000'&$select=Account,AccountIsCustomer = lijst nog te groot, geeft klanten contact personen
                ///crm/Contacts?$filter=AccountIsCustomer eq true = contacten is customer geeft alle contacten van bedrijf terug
                ///crm/Accounts?$select=Type = geeft type A, accounts terug
                ///crm/Accounts?$select=AccountManager
                ///////////////////////////////////
                ///crm/Contacts?$filter=IsMainContact eq true and AccountIsCustomer eq true === te weinig data???
                //////////////////////////////////

                var response = client.SendAsync(request).Result;

                //if the response is successfull, set the result to the workitem object
                if (response.IsSuccessStatusCode)
                {
                    //als we tot hier geraakt zijn, gaan we ervan uit dat we alle contacten en companies hebben kunnen binnenhalen,
                    //dus hier verwijderen we de contacten lijst om nadien een clean add te doen voor contacten per bedrijf.
                    if (m_context.Contacts.ToList() != null)
                    {
                        var OLDContactList = m_context.Contacts.ToList();
                        foreach (var contact in OLDContactList)
                        {
                            m_context.Contacts.Remove(contact);
                            m_context.SaveChanges();
                        }
                    }



                    var result      = response.Content.ReadAsStringAsync().Result;
                    var rawResponse = JsonConvert.DeserializeObject <ExactCompany>(result);

                    var list = m_context.Company.ToList();
                    foreach (var Company in rawResponse.d.results)
                    {
                        var result2 = list.FirstOrDefault(x => x.Name == Company.Name);
                        if (result2 == null)
                        {
                            m_exactOnlinService.AddCompany(Company.Name, Company.AddressLine1, Company.Email, Company.Code, Company.Website, Company.Phone, Company.Postcode, Company.CountryName, Company.City);
                        }
                        else
                        {
                            var updateCompany = m_context.Company.FirstOrDefault(x => x.Name == Company.Name);

                            updateCompany.Phone      = Company.Phone;
                            updateCompany.Address    = Company.AddressLine1;
                            updateCompany.Email      = Company.Email;
                            updateCompany.Code       = Company.Code;
                            updateCompany.Postalcode = Company.Postcode;
                            updateCompany.Country    = Company.CountryName;
                            updateCompany.City       = Company.City;

                            m_context.SaveChanges();
                        }
                        GetMainContact(Token, Division, Company.MainContact, Company.Name);
                    }
                }
            }
        }