示例#1
0
        /// <summary>
        /// Синхронизация счетов
        /// </summary>
        private async Task SyncAccounts(ISyncPipeServer sps)
        {
            var remAccounts = await sps.GetAccountList();

            if (remAccounts == null)
            {
                return;
            }

            var accounts = _accountDA.GetAccounts();

            foreach (var racc in remAccounts)
            {
                if (_account_rid_lid.ContainsKey(racc.AccountID))
                {
                    int lid     = _account_rid_lid[racc.AccountID];
                    var account = accounts.FirstOrDefault(r => r.AccountID == lid);
                    if (account != null) // локальный найден
                    {
                        bool isUpdate = false;
                        if (account.AccountType != racc.AccountType)
                        {
                            account.AccountType = racc.AccountType; isUpdate = true;
                        }
                        if (account.Code != racc.Code)
                        {
                            account.Code = racc.Code; isUpdate = true;
                        }
                        if (account.Name != racc.Name)
                        {
                            account.Name = racc.Name; isUpdate = true;
                        }
                        if (account.CommPerc != racc.CommPerc)
                        {
                            account.CommPerc = racc.CommPerc; isUpdate = true;
                        }
                        if (account.IsShortEnable != racc.IsShortEnable)
                        {
                            account.IsShortEnable = racc.IsShortEnable; isUpdate = true;
                        }

                        if (isUpdate)
                        {
                            _accountDA.UpdateAccount(account);
                        }
                    }
                    else // соответствие есть, но локальный не найден, значит соответствие уже не действительно
                    {
                        var acc = _accountDA.CreateAccount(racc.Code, racc.Name, racc.CommPerc, racc.IsShortEnable, racc.AccountType);
                        _account_rid_lid[racc.AccountID] = acc.AccountID; // прописываем новый ключ
                    }
                }
                else // соответствие не найдено
                {
                    var acc = _accountDA.CreateAccount(racc.Code, racc.Name, racc.CommPerc, racc.IsShortEnable, racc.AccountType);
                    _account_rid_lid.Add(racc.AccountID, acc.AccountID);
                }
            }
        }