private async Task UpdateAccountGroupsAsync(IEnumerable <AccountGroupSyncDTO> accountGroups)
        {
            if (accountGroups == null || !accountGroups.Any())
            {
                return;
            }

            foreach (var accountGroup in accountGroups)
            {
                var userId = (await this.userRepository.GetFirstUserAsync()).Id;
                var accountGroupToUpdate = await this.accountGroupRepository.GetAccountGroupAsync(accountGroup.ExternalId);

                if (accountGroupToUpdate != null)
                {
                    if (accountGroupToUpdate.ModifiedOn < accountGroup.ModifiedOn)
                    {
                        accountGroupToUpdate.Edit(accountGroup.Name, userId);
                        accountGroupToUpdate.Delete(accountGroup.IsDeleted);
                        accountGroupToUpdate.SetModifiedOn(accountGroup.ModifiedOn);
                        await this.accountGroupRepository.UpdateAsync(accountGroupToUpdate);
                    }
                }
                else
                {
                    var accounGroupToAdd = AccountGroup.Create(accountGroup.Name, userId, accountGroup.ExternalId);
                    accounGroupToAdd.Delete(accountGroup.IsDeleted);
                    accounGroupToAdd.SetModifiedOn(accountGroup.ModifiedOn);
                    await this.accountGroupRepository.AddAccountGroupAsync(accounGroupToAdd);
                }
            }
        }
Example #2
0
        public async Task <AccountGroup> GetAccountGroup(string tradingConditionId, string baseAssetId)
        {
            var accountGroup = await _accountGroupRepository.GetAsync(tradingConditionId, baseAssetId);

            return(accountGroup == null ? null : AccountGroup.Create(accountGroup));
        }