static void AccountSync()
        {
            int page        = 1;
            var crmAccounts = crm.GetAccounts(500, page);

            void Execute()
            {
                foreach (var account in crmAccounts.Entities)
                {
                    try
                    {
                        FreshdeskAccountForCreation freshdeskAccount = accountMapper.CreateAccount(account);

                        if (account.Contains("isw_freshdeskid"))
                        {
                            long freshdeskId = long.Parse(account["isw_freshdeskid"].ToString());
                            freshdesk.UpdateAccount(freshdeskId, freshdeskAccount);
                        }
                        else
                        {
                            FreshdeskAccountDto createdFreshdeskAccount = freshdesk.CreateAccount(freshdeskAccount);

                            if (createdFreshdeskAccount != null)
                            {
                                Entity accountEntity = accountMapper.CreateAccount(createdFreshdeskAccount);

                                crm.UpsertAccount(accountEntity);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            do
            {
                Execute();
                page++;

                if (crmAccounts.MoreRecords)
                {
                    crmAccounts = crm.GetAccounts(500, page, crmAccounts.PagingCookie);
                }
                else
                {
                    break;
                }
            } while (crmAccounts.MoreRecords);

            UpdateAppsettings("AccountLastSyncDate", 2);
        }
        public Entity CreateAccount(FreshdeskAccountDto account)
        {
            Entity accountEntity = new Entity("account");

            if (account == null)
            {
                return(accountEntity);
            }

            accountEntity["name"]            = account.Name;
            accountEntity["isw_freshdeskid"] = account.Id.ToString();

            return(accountEntity);
        }
예제 #3
0
        public FreshdeskAccountDto UpdateAccount(long accountId, FreshdeskAccountForCreation freshdeskAccountForCreation)
        {
            FreshdeskAccountDto freshdeskAccountDto = null;

            string         responseBody = String.Empty;
            HttpWebRequest request      = FreshdeskHttpClient.GetRequestMessage("PUT",
                                                                                $"/api/v2/companies/{accountId}");

            string data = JsonConvert.SerializeObject(freshdeskAccountForCreation);

            byte[] byteArray = Encoding.UTF8.GetBytes(data);
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            responseBody = WriteRequest(request, byteArray);

            freshdeskAccountDto = JsonConvert.DeserializeObject <FreshdeskAccountDto>(responseBody);

            return(freshdeskAccountDto);
        }